Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imeOptions "actionNext" programmatically - how to jump to next field?

In layout XML it is possible to specify android:imeOptions="actionNext" which adds Next button in virtual keyboard and by clicking on it - focus jumps to the next field.

How to do this programmatically - e.g. based on some event trigger focus to go to the next field?

like image 379
Laimoncijus Avatar asked Aug 11 '10 14:08

Laimoncijus


5 Answers

You can use the constants from EditorInfo class for the IME options. like,

editText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
like image 183
Firewall_Sudhan Avatar answered Nov 17 '22 16:11

Firewall_Sudhan


Search for the next focusable field and than invoke requestFocus().

TextView nextField = (TextView)currentField.focusSearch(View.FOCUS_RIGHT);
nextField.requestFocus();
like image 34
Justin Avatar answered Nov 17 '22 15:11

Justin


Just suggestion, if you are using

     EditTextSample.setImeOptions(EditorInfo.IME_ACTION_DONE); 

it doesn't work, make sure that your EditText is using a single line.

Eg:

       editTextSample.setSingleLine();
like image 26
ziniestro Avatar answered Nov 17 '22 17:11

ziniestro


There is always necessity to add extra keys apart from default keys available in virtual QWERTY keyboard.

Using XML

<EditText android:text="@+id/EditText01" 
android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:imeOptions="actionDone"/>

By Programmatic Way

An EditorInfo is most useful class when you have to deal with any type of user input in your Android application.

IME_ACTION_DONE: This action performs a “done” operation for nothing to input and the IME will be closed.

 EditTextSample.setImeOptions(EditorInfo.IME_ACTION_DONE);

For more information you may visit http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html

like image 7
IntelliJ Amiya Avatar answered Nov 17 '22 16:11

IntelliJ Amiya


The kotlin pendant

editText.imeOptions = EditorInfo.IME_ACTION_DONE
like image 1
kuzdu Avatar answered Nov 17 '22 15:11

kuzdu