How to get keyboard to move to next textfield - keyboard

I have several UITextFields that are in a group... I need to be able to move from the first to the last, and on the last make it FirstResponder.
I thought the Next key would move the focus, and Done would cause it to become FirstResponder, but apparently not.
Ideas?

The "Accepted Answer" is right, but I thought a little code wouldn't hurt for people who are new to MonoTouch.
public override void ViewDidLoad () {
base.ViewDidLoad ();
// make first text field have focus
this.txtMake.BecomeFirstResponder();
// make 'return' shift focus to next text field
this.txtMake.ShouldReturn = delegate(UITextField textField) {
this.txtModel.BecomeFirstResponder ();
return true;
};
// make 'return' on last text field save and close the form
this.txtModel.ShouldReturn = delegate(UITextField textField) {
this.txtModel.ResignFirstResponder();
this.SaveAndClose ();
return true;
};
}
private void SaveAndClose() {
// todo: do something with your data
// navigate back
this.NavigationController.PopViewControllerAnimated(true);
}
Hope this helps others.

You have to implement the UITextFieldDelegate's ShouldReturn method and in there make the next text field BecomeFirstResponder(). Then return/next will take you to the next field. If return is hit on the last textfield you will call ResignFirstResponder() on that field.

You have to manually move the view that contains the text fields, in a way that the text field you want is above the keyboard.

Related

How to wirte Public Dialog addClickListener write back Form TextField

I’m a beginner, I can’t pass this level, please help.
I have a lot of forms with TextField (cust_no, cust_name), each with a button on the right,
press the button
A dialog can be display custom record, after selecting the required customer,
Write the selected cust_no, cust_name back to the Text_Field of Form.
I hope to write dialog as a public class, so that many class Forms can use this function, and can also smoothly write cust_no and cust_name back to their respective Form TextField.
In addition to backfilling cust_no,cust_name TextField for some Forms, some also need to query the consumption amount and write back the specified cust_amt TextField.
My trouble is that form button.addClickListener open a dialog,
Dialog’s Button_OK.addClickListener cannot know how I want to write back Form TextField and some have special query mechanisms, how to customize
Without seeing exactly how your code is structured, I can only give a quite generic answer. What you need is typically that something associated with the button for opening the dialog can know what to do with the result from the dialog, and it can also configure the dialog's OK button to carry out that action.
public class HelloWorldView extends VerticalLayout {
public HelloWorldView() {
TextField customerNumberField = new TextField("Customer number");
TextField customerNameField = new TextField("Customer name");
Button nameDialogButton = new Button("Open dialog", dialogOpenClick -> {
showDialog(customer -> {
customerNumberField.setValue(customer.getNumber());
customerNameField.setValue(customer.getName());
});
});
add(customerNumberField, customerNameField, nameDialogButton);
}
private void showDialog(Consumer<Customer> selectionAction) {
Select<Customer> customerSelect = new Select<>(new Customer("1", "Customer 1"),
new Customer("2", "Customer 2"));
customerSelect.setTextRenderer(customer -> customer.getName());
Dialog dialog = new Dialog();
dialog.add(customerSelect);
dialog.add(new Button("Select customer", click -> {
Customer selectedCustomer = customerSelect.getValue();
if (selectedCustomer != null) {
selectionAction.accept(selectedCustomer);
}
dialog.close();
}));
dialog.open();
}
}

How to get all selected rows data in javafx

there is a problem!!
In javafx table view i applied multiple selected mode by Shift+mouseClick or Clt+MouseClick. By This
tblViewCurrentStore.setOnMouseClicked(new EventHandler<MouseEvent>() {
#Override
public void handle(MouseEvent event) {
tblViewCurrentStore.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
}
});
it's ok on GUI but problem is, if i use this code it give me the last selection cell's value,
private void btnDeleteOnAction(ActionEvent event) {
System.out.println(tblViewCurrentStore.getSelectionModel().getSelectedItem().getProductName().toString());
}
Out Put SAMSUNG HDD
but when i use this code it give this!
private void btnDeleteOnAction(ActionEvent event) {
System.out.println(tblViewCurrentStore.getSelectionModel().getSelectedItems().toString());
}
It Give me This types of output
[List.ListProduct#3a22ea22, List.ListProduct#6d99efa2, List.ListProduct#40fd0f67]
But i need when i select multiple row then press delete it will show all selected data like first one.
Hear is my GUI(With multiple selection)
You can even use this :
ArrayList<YourModel> products = new ArrayList<>(table.getSelectionModel().getSelectedItems());
for (YourModel model : models) {
System.out.println(model);
}
//OR
final List<YourModel> collect = table.getSelectionModel().getSelectedItems().stream().collect(Collectors.toList());
There are multiple problems with your code:
tblViewCurrentStore.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);only needs to be set once (thus its a setter). Do it after your TableView has been initialized and not on every click.
SelectionModel#getSelectedItem() clearly says what it does:
Returns the currently selected object (which resides in the selected index position). If there are multiple items selected, this will return the object contained at the index returned by getSelectedIndex() (which is always the index to the most recently selected item).
And finally SelectionModel#getSelectedItems returns all selected objects (as in Java Objects).
So if you want the names, you can something like this:
List<String> names = tblViewCurrentStore.getSelectionModel().getSelectedItems().stream()
.map(ListProduct::getProductName)
.collect(Collectors.toList());

UICollectionview SelectItem programmatically not changing background

I have a UICollectionView with images. The user can select (multiselect) the images. When the user taps a single image, everything works fine. The SelectedBackgroundView is visible and on tap again, the normal image is visible.
But my problem is, I have a option for the user "Select all". In that i want to select all items programmatically. With following code:
for (int i = 0; i < CollectionView.NumberOfItemsInSection(0); i++)
{
var ip = NSIndexPath.FromItemSection(i, 0);
CollectionView.SelectItem(ip, false, UICollectionViewScrollPosition.None);
}
The following method returns the correct number for the selected items:
var number = CollectionView.GetIndexPathsForSelectedItems().Length;
But the UI is not changing to the SelectedBackgroundView.
Can anyone help me? Thanks.
Calling SelectItem does not cause the display to be updated; it just changes the Selected property of the UICollectionViewCell therefore updating the selected index set in the collection view.
What I do is override the Selected property of my UICollectionViewCell implementation and adjust the UI at that point:
public class MyCell : UICollectionViewCell
{
// ...
public override bool Selected
{
get { return base.Selected; }
set
{
base.Selected = value;
// change the state of the selected background
imageBackground.Image = LoadAnImage(value ? "BackgroundOn" : "BackgroundOff");
}
}
}
This way ensures that the UI is updated at all possible points when the selected state of the cell changes, either by user interaction or programmatically calling SelectItem or DeselectItem on the collection view.
I do not personally use the SelectedBackgroundView property on a cell (I do my own layering, most of the time), but you may have to manually bring that view to the front yourself in a similar Selected property override.

getText from one layout and (setting it) setText in an other layout

i call this method SolveUpdation (from button- onclickAction Listener) from mainAcitivity with main layout. i use other layout to get value from user and set it as button title in the main layout and that is only instruction that does not works for me
private void SolveUpdation() { //this function call is generated from the main Activity with main layout
setContentView(R.layout.updateappliance); //this is 2nd layout to get values from user and use them as buttonText in the main layout
btnSaveApp = (Button) findViewById(R.id.Bupdatenow);
btnSaveApp.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
mOutEditText = (EditText) findViewById(R.id.edit_text_1);
TextView view1 = (TextView) findViewById(R.id.edit_text_1);
final String TitleApp1 = view1.getText().toString(); //the value is read properly here
// if (App1.length() > 0) {
// byte[] send = App1.getBytes();
// }
btnSaveApp.setText(TitleApp1); //this works fine
startActivity(new Intent(HomeScreen.this, HomeScreen.class));//this the main activity for main layout
setContentView(R.layout.main); //this is the main layout and this instruction works
buttonLED1.setText(TitleApp1); //buttonLED1 (a Togglebutton or can be simple) is defined in main layout and this does not works and this is what i am stuck with
SaveAppNamesToast(TitleApp1); //this is just to toast the value and it works fine.
}});
So plz can any one guide me why this instruction buttonLED1.setText(TitleApp1); does not works ??? Any help will be appreciatable.. thanks
No offense, but the way you write your code is not a good practice.
My advise: Stop calling another setContentView in your Main Activity. You should rather implement all needed Buttons and EditTexts in one layout and set their visiblity to gone or visible depending on which button was clicked.
If you don't wanna do this you should create a second class that handles the input of the user. After pressing the save button you initialize your intent for the main activity and give it via intent.putExtra("KEY", value) the input of the user.
Your Main Activity can receive this value via getIntent().getExtras().getInt("KEY").
By the way: I think your current code doesn't work because of the new Activity you start. Through this everything gets initialized again so the buttonLED1 that you see isn't the same buttonLED1 that gets the text.

JavaFX scroll events handling for TableView

I have a problem with my JavaFX project. There is a moment I can't understand. As far as I understand the following code should be able to handle all scrolling events of a table, which is an instance of TableView
table.setOnScroll(new EventHandler<ScrollEvent>() {
#Override
public void handle(ScrollEvent scrollEvent) {
System.out.println("Hello!");
int i = 0;
int length = table.getItems().size();
for(Node n: table.lookupAll("TableRow")) {
if (n instanceof TableRow) {
TableRow row = (TableRow) n;
if(table.getItems().get(i).getType() == "fwfx") {
row.setStyle("-fx-background-color: forestgreen;");
}
i++;
}
if(i == length) {
break;
}
}
}
}
);
Whenever I launch the application it highlights row correctly only for visible rows. I found it out because
table.lookupAll("TableRow")
returns the set of only 17 nodes for me. although
table.getItems().size()
shows the correct number of rows. If I scroll down the table I see unapproipriate rows highlighted. I'm lost a bit.
So the question is how do I correctly handle the scroll events for my table? I need to process all rows of the table, not only visible.
So finally I found the way to handle scrolling events and I would like to share my experience. Using the Scenic View I found that TableView setOnScroll event is fired only when you scroll the mouse wheel with cursor over the column headers. But to be able to handle ScrollEvent when the cursor is above table data (what I needed in my example) one needs to use the EventFilter to be sure. For example, the colde below will handle all scrolling events of TableView's instance
table.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() {
#Override
public void handle(ScrollEvent scrollEvent) {
System.out.println("Scrolled.");
}
});
Scenic View also gave me a hint about what TableView consists of after
stage.show()
has worked.
Althougth I still have incorrectly highlighted rows)...
Listen to scroll bar value changes
for (Node node : dataTable.lookupAll(".scroll-bar"))
{
if (node instanceof ScrollBar && ((ScrollBar) node).getOrientation().equals(Orientation.VERTICAL))
{
((ScrollBar) node).valueProperty().addListener(formatBUIScrollChangeEventHandler);
}
}
This will be triggered in any form of scrolling on the table.
Have been spending hours then finally come out with this idea when solving my own situation.
The question is old, but you haven't posted/accepted an answer yet.
So, this schould help: tableView.refresh(). It's available in JavaFX since Java 8u60.
You have to call it inside your ScrollEvent. Also perhaps by sorting and dragging ScrollBar (see my answer here).

Resources