ImeAction search changed to "Finish" after clicking on it

I have an Edittext to search in a Listview.

I set imeOptionto 'IME_ACTION_SEARCH' so that the soft keyboard displays the search key on it.

The problem is that when I press the search key on the keyboard, if there is no text in the editor, the search key changes to "Finish", and not to turn off the keyboard.

If the Edittext contains some text, the search key works well.

Keyboard before tapping on Search

Keyboard after tapping Search

+4
source share
3 answers

. , OnEditorAction Edittext. , onEditorAction().

0

XML

<EditText android:imeOptions="actionSearch" />

Java

yourTextField.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

.

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.
        }
    }
});
+1

you have to do this for your edittext in xml

     android:imeOptions="actionSearch|actionSearch"

it will show you the search button always!

0
source

All Articles