I have 5 edit texts where user enters his options, I keep first two visible and other 3 visibility gone. If user wants to enter option 3 I make it visible by pressing action next key on keyboard while user finishes typing on option 2. But the problem is it doesnt focus on edit text 3. Now to experiment visibility of edittext 3 from gone to invisible, action next method works well. Is there a way to make input next method work when view's visibility turns gone to visible?
I am using this code to make focus appear on edittext 3 which is not working in case of edittext visibility turning visible from gone. Same code works well in case of edittext visibility turning visible from invisible.
option2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_ACTION_NEXT){
option3.setVisibility(View.VISIBLE);
option3.requestFocus();
}
return false;
}
});
How to make focus on button3 :
button2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
button3.setVisibility(View.VISIBLE);
button3.requestFocus();
}
return false;
}
});
Related
I have an 2 edit texts, one of them is visible and other is not. I have set visibility "gone" for the invisible one. Now when I click input method next from edittext one, I make edittext two visible and request focus there, it gets visible but focus is not there. Interesting thing is I made visibility "invisible" instead of "gone". here is the code...
option1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_ACTION_NEXT){
option2.setVisibility(View.VISIBLE);
option2.requestFocus();
}
return false;
}
});
I am not sure it will work or not.
But your setOnEditorActionListener() is returning false, make it to return true.
Showing EditText in ListView adapter issue coming into focus:
Each List item has three EditText. I want to change the focus horizontally.
I am successfully able to move focus from the first to the third EditText using this code.
The issue is coming when I press softkeyboard next. I want to move the focus to the next list row, first EditText. However, when I use this code given below the focus switches to the same list, first EditText
holder.edtStock.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
if(holder.edtStock.hasFocus())
holder.edtOrderStock.requestFocus();
return true;
}
return false;
}
});
holder.edtOrderStock.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
if(holder.edtOrderStock.hasFocus())
holder.edtStock.requestFocus();
return true;
}
return false;
}
});
I want to achieve this:
In your EditText using android:nextFocusForward="#+id/edtNumeroInterior" and android:imeOptions="actionNext"
if you want to change to down using nextFocusDown
I have two EditTexts. Is there a way to code the program in a way that changing one EditText would change the other?
For example, if chicken is 200 calories per 100 grams, then changing the EditText of chicken to 100 will result in an auto update of 100 grams to 50 grams, without clicking anything.
You could install an OnEditorActionListener on your EditText and perform the action when the user stops typing:
myEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
myEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// call some other function to test the value and
// set the result on the other EditText
return true;
}
return false;
}
});
I have an Activity with two EditText fields. So when I press enter in the first one the second one becomes focused.
However I want to disable Enter key in the first EditText sometimes (for example when I think that the user haven't made a proper input into the first EditText).
I' ve overwriten onKeyDown for the 1st EditText returning true when key event is KEYCODE_ENTER but that doesn't help.
What shall I do?
How about adding an OnFocusChangeListener? When your EditText looses focus, you can do validation and can do a requestFocus for the "right" field.
Just by adding an editorActionListener:
editText1.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if(isValidContent(editText1.getText().toString()){
editText2.requestFocus();
return true;
} else {
....
}
}
return false;
}
});
I have an activity with two EditTexts. If, in landscape mode, I select the first EditText, the keyboard that is displayed has a "next" button which should allow me to type in the second EditText. Likewise, the second EditText has a "done" button, which I would like to handle for completing the activity. How can I handle the selection of these buttons?
There is fairly little documentation on how to solve this issue. I found a good solution here. Basically, you can add an IMEoption for each of the EditTexts:
For the first one:
android:imeOptions="actionNext"
For the second one:
android:imeOptions="actionDone"
To handle these in the code, try something like this:
EditText departureAddress, destinationAddress;
departureAddress = (EditText)findViewById(R.id.departure);
//Set the action of the "next" button to bring destinationAddress to focus
destinationAddress(new OnEditorActionListener(){
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
destinationAddress.requestFocus();
}
return true;
}
});
destinationAddress = (EditText)findViewById(R.id.destination);
//Set the action of the "done" button to handle the map query
destinationAddress.setOnEditorActionListener(new OnEditorActionListener(){
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
//Handle map query
}
return true;
}
});