We enter value in first EditText
. Now I want when we press done button then cursor move to next EditText
.
I tried to do it and search on Google but nothing found.
We enter value in first EditText
. Now I want when we press done button then cursor move to next EditText
.
I tried to do it and search on Google but nothing found.
You can get DONE
button click and set focus to next EditText
first_edit_text.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == 0 || actionId== EditorInfo.IME_ACTION_DONE)
{
next_edit_text.requestFocus();
}
return false;
}
});
EDIT :
To fulfill your requirement :
public void setEditText() {
edittext = new EditText[length];
for (int i = 0; i < length; i++) {
edittext[i] = new EditText(this);
edittext[i].setId(i);
edittext[i].setSingleLine();
edittext[i].setImeOptions(EditorInfo.IME_ACTION_DONE);
edittext[i].setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == 0 || actionId == EditorInfo.IME_ACTION_DONE) {
int current_id= v.getId();
if((current_id+1)!=length){
edittext[current_id+1].requestFocus();
}
}
return false;
}
});
linear.addView(edittext[i]);
}
}
Please use imeOptions in EditText.
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="32dp"
android:layout_marginTop="16dp"
android:imeOptions="actionNext"
android:ems="10" >
<requestFocus />
</EditText>
You can try triggering Next key's click in onClick
of DONE key as shown here:
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Activity.dispatchKeyEvent(KeyEvent.KEYCODE_NEXT); //trigger Next key's click here
}
return false;
}
});
Hope that helps.
After entering the value in the text, to go to next edit box you can type in the xml layout editbox code as following:
android:nextFocusDown="@+id/here your next edit box id"
If you place android:singleLine="true"
on your EditText
it will automatically change the Enter button on your keyboard into a Next button.