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.
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.
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With