Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImeAction Search is changed to Done after tapping on it

I have an Edittext for searching on Listview.

I have set imeOption to 'IME_ACTION_SEARCH' so that soft-keyboard will show search key on it.

The problem is that when I tap on search key on keyboard if edittext contains no text in it, the search key changes to 'Done' instead of dismissing the keyboard.

If the Edittext contains some text in it the search key works well.

Keyboard before tapping on Search

Keyboard after tapping Search

like image 904
Aju Avatar asked Nov 11 '22 21:11

Aju


1 Answers

In your XML layout file you can set

<EditText android:imeOptions="actionSearch" />

Or in your Java source file you could do

yourTextField.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

Then you can override the listener for the search event.

yourTextField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) { 
            //if textfield value is empty then close keyboard.
            //else call your search function.
        }
    }
});
like image 80
Ryan Burke Avatar answered Nov 15 '22 01:11

Ryan Burke