2

i am using android:imeOptions="actionSearch"

in editText and my question is can i write my own event if user presses Searchbutton on Softkeyboard?

actualy i want to perform functionality of softkeyboard search button similar to button we use on android activity.

any help would be appriciated.

UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278

2 Answers2

6

This is what I ended up using:

EditText SearchEditText = (EditText) findViewById(R.id.txtMapSearch);
SearchEditText.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
        // TODO Auto-generated method stub
        if (arg1 == EditorInfo.IME_ACTION_SEARCH) {
            // search pressed and perform your functionality.
        }
        return false;
    }
});
nikib3ro
  • 20,366
  • 24
  • 120
  • 181
UMAR-MOBITSOLUTIONS
  • 77,236
  • 95
  • 209
  • 278
5

Call setOnEditorActionListener() on the EditText to register a TextView.OnEditorActionListener that will be invoked when the user taps the action button on the soft keyboard.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Look at the BluetoothChat sample that shipped with your SDK, also online at http://developer.android.com/resources/samples/BluetoothChat/index.html -- or look at this SO question: http://stackoverflow.com/questions/1538331/android-cant-figure-how-to-use-setimeactionlabel – CommonsWare Apr 07 '10 at 12:34