Can any one tell me how to pass the value of textview (if there are five value in textview and we pass only one) from one screen to its next screen. Consider the case: I'm having two screens, first screen with one textview and the second activity have one textview and button.
If I click the first value then it has to move to second activity textview.
In order to pass state information between screens, you need to first define your Intent which you will pass to startActivity(), then use the putExtra() method on the Intent to add extra information to it.
Intent i = new Intent();
i.setClassName("com.example", "com.example.newscreen");
i.putExtra("string1", "some string");
i.putExtra("string2", "some other string");
startActivity(i);
Now to get the values on the next screen, you'd do something like this:
Intent i = getIntent();
Bundle b = i.getExtras();
String string1 = b.getString("string1");
String string2 = b.getString("string2");
Related
I have an Actor BP, inside this BP I have a UWidgetComponent with a Widget Class already selected in the Details, and that Widget Class has a TextBlock. Now, inside this BP I also have a C++ USceneComponent, this component is in charge of showing a random text, in the TextBlock mentioned above, each time the user presses a button.
This is in my USceneComponent's header file (.h)
class UWidgetComponent* QuestionWidget;
class UQuestionProjectionText* QuestionText;
class UTextBlock* QuestionTextBlock;
Then in the ".cpp" file, in the constructor
QuestionWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("CodeQuestionWidget"));
QuestionTextBlock = CreateDefaultSubobject<UTextBlock>(TEXT("CodeTextBlock"));
Then in the BeginPlay()
//Gets the WidgetComponent from the BP
QuestionWidget = Cast<UWidgetComponent>(GetOwner()->GetComponentByClass(UWidgetComponent::StaticClass()));
if (QuestionWidget)
{
QuestionWidget->InitWidget();
//Gets an instance of the UMyUserWidget class, from the UWidgetComponent in the BP
QuestionText = Cast<UMyUserWidget>(QuestionWidget->GetUserWidgetObject());
this->QuestionTextBlock = QuestionText->QuestionTextBlock;
//Sets the text to an empty String
QuestionTextBlock->SetText(FText::FromString(""));
}
else
{
UE_LOG(LogTemp, Error, TEXT("QuestionWidget was not found"));
return;
}
Then in the TickComponent(), when the user presses the button, I use a something that looks like this
QuestionTextBlock->SetText(FText::FromString(QuestionStringsArray[9]));
The problem is that when I press the button, the text does not change in the Widget, but if I print the text that I'm passing, it does print the string, so I'm not passing an empty value to the "SetText()".
Another weird thing, is that the line in the BeginPlay that sets the text, that one works, I have changed it to a random string, instead of an empty one, and it does display it.
I don't know if when I do the "QuestionWidget->InitWidget();" I'm creating a new one separate from the one in the BP, or if I'm just missing something. If I eliminate the "QuestionWidget->InitWidget()" the widget gets initialized on time sometimes, and sometimes it doesn't.
I have some error handling in my code, but eliminated it here so that it didn't look too messy. But also, none of the Errors popup, everything goes on smoothly, only that the Widget doesn't show the updated Text.
If there is an inherited variable called id, I would like to display widget.index and ": problem number" together on one line on the screen.
ex)
problem(text) 1(list variable)
problem(text) 2(list variable)
Is there a way to get a variable in a list like the one above and display it on the screen along with text?
You can use $ in a string
String someString = 'problem id: ${problem(text)} and widget index :${widget.index}';
I'm trying to get user's latest mouse click in order to display the right table. However, I can't find any way to implement this idea. How do i get user's latest mouse click by using mouseEvent function?
I tried using if else statements but it doesn't work when there is still value in the monstersTable1
def handleEditMonster(action : ActionEvent) = {
val selectedMonster1 = monstersTable1.selectionModel().selectedItem.value
val selectedMonster2 = monstersTable2.selectionModel().selectedItem.value
if (selectedMonster1 != null){
val okClicked = MainApp.showMonsterEditDialog(selectedMonster1)
if (okClicked) showMonstersDetails(Some(selectedMonster1))
} else if (selectedMonster2 != null) {
val okClicked = MainApp.showMonsterEditDialog(selectedMonster2)
if (okClicked) showMonstersDetails(Some(selectedMonster2))
} else {
// Nothing selected.
val alert = new Alert(Alert.AlertType.Warning){
initOwner(MainApp.stage)
title = "No Selection"
headerText = "No monsters Selected"
contentText = "Please select a monsters in the table."
}.showAndWait()
}
}
I want it to be able to access the second table even though selectedMonster1 is still != null
It's not entirely clear from your question what it is you're trying to do, so please bear with me... (For future reference, it's best if you can create a ''minimal, complete and verifiable example'' that illustrates your problem.)
I'm assuming that you have two scalafx.scene.control.TableView instances, referenced via monstersTable1 and monstersTable2. You want to allow the user to select either one of the monsters in the first table, or one of the monsters in the second table, but not to be able to select one monster from each table simultaneously.
I'm unclear when your handleEditMonster function is called, so I'm guessing that it's invoked when the user clicks, say, an Edit Monster button, as that button's clicked event handler.
Do I have that right?
Assuming the above is accurate, you should listen for changes in table selection, and clear the selection in the other table when a new selection is made. The currently selected item in each table is a property that we can add a listener to, so we can achieve this with the following code (in your scene's initialization):
// In the onChange handlers, the first argument references the observable property
// that has been changed (in this case, the property identifying the currently
// selected item in the table), the second is the property's new value and the third
// is its previous value. We can ignore the first and the third arguments in this
// case. If the newValue is non-null (that is, if the user has made a
// selection from this table), then clear the current selection in the other
// table.
monstersTable1.selectionModel.selectedItem.onChange {(_, newValue, _) =>
if(newValue ne null) monstersTable2.selectionModel.clearSelection()
}
monstersTable2.selectionModel.selectedItem.onChange {(_, newValue, _) =>
if(newValue ne null) monstersTable1.selectionModel.clearSelection()
}
This should do the trick for you, and your handleEditMonster function should now work. You might want to add an assertion to guard against both tables having a current selection, which would indicate a bug in the selection handler logic.
having registered a long press at a point on the map, I'd like a text field to pop up, so I can set the input as the title of a pin dropped at that point. How would I go about doing this?
Heres my code which currently registers a longpress and drops a pin, that all works fine! I'm not sure how to bring up a text field and get the users input though
func DropPin(gestureRecognizer:UIGestureRecognizer) {
if gestureRecognizer.state == .Began {
var point:CGPoint = gestureRecognizer.locationInView(self.Map)
var pinLoc: CLLocationCoordinate2D = self.Map.convertPoint(point, toCoordinateFromView: self.Map)
let x = CustomAnnotation(coordinate: pinLoc, title: "Pin", subtitle: "Pin", imageName: "TouchPin")
self.Map.addAnnotation(x)
}
}
There are several ways to do so, but you can choose one of the two for example.
In your view, you add a text field where the user set the title before you drop the pin. But that might not be intuitive or look bad (if you need to have a full screen map for example).
So, what I would suggest is to fire an UIAlertController with a text field inside. Here is an example of how you could do it.
Either you :
Create the annotation
Add it to the map
An alert appear
The user enter a name (keep it somewhere)
You retrieve the last annotation you've added
You set it's title with the name entered previously
Or :
You detect your long press
An alert appear
The user enter a name (keep it somewhere)
Create your annotation with the name entered previously
Add it to the map
Those are just 2-3 examples. You might think of something else :)
I have created one sstatic Arraylist and displayed the data in listview using the custom adapter. My requirement is when i click on the listitem, i have to show the details of particular listitem in the next screen. How can i pass the selected listitem data from listview screen to details screen.
I have tried to pass the data using the parcelable concept. But when I click on the listitem, i am getting "Null pointer exception"
Any complete example will be very helpful.
Thanks in advance.
It can be acheived in following way.I'm assuming that your list item is a text view.
Add onItemClick Listener to your listview,get Selected Item's text on click and pass it with itent extras to NextActivity.
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View p_view,
int p_pos, long arg3) {
TextView text= (TextView ) p_view.findViewById(R.id.textview1); //id of textview from layout file that you are inflating.
String mytext=text.getText();
Intent i = new Intent(Context context,NextActivity.class);
i.putExtra("text",mytext);
startActivity(i);
}
});
And on the next activity,retreive the text from extras.
Bundle extras = getIntent().getExtras();
String text_value= extras.getString("text");