Android: text edit button

I have an edit text that is defined as follows.

<EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:maxLines="1" android:inputType="text" android:hint="@string/field_text" android:id="@+id/field" /> 

I want to configure a custom command so that when someone clicks the Finish / Go button on the on-screen keyboard, the button is pressed, or it simply starts the methods launched by the button. I think this has something to do with ime options, but I could not understand how they work. Thanks in advance for your help!

+48
android ime edit
Jul 18 '10 at 17:05
source share
2 answers

You need a combination of android: imeOptions and setOnEditorActionListener

 <EditText android:id="@+id/some_edittext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:imeOptions="actionSend"> </EditText> some_edittext.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND) { some_button.performClick(); return true; } return false; } }); 

Obviously, you should change the actionSend to the desired action and change IME_ACTION_SEND accordingly.

+115
Jul 18 '10 at 20:59
source share
β€” -

Take a look at the setImeActionLabel method (or imeActionLabel and imeActionId ) and setOnEditorActionListener to configure the listener to respond to events.

0
Jul 18 '10 at 20:13
source share



All Articles