I'm creating a search option in an android application.
After pressing "Search" on the screen-keyboard an event triggers which sends the query to the server.
What I want to do is disable the "Search" button on the screen-keyboard when no text has been typed in it's corresponding EditText
yet.
I added this to the EditText
:
android:imeOptions="actionSearch"
So that's why the keyboard has got a "Search" button in stead of the default "enter"/"done". (Just in case you where wondering).
What should I set to disable EditText? It's possible to preserve both the style of the view and the scrolling behaviour. To disable an EditText while keeping this properties, just use UI. setReadOnly(myEditText, true) from this library.
We cannot disable the action button on the android keyboard. You will have to settle with checking for empty string in editor action listener.
setOnEditorActionListener(new TextView.OnEditorActionListener() {
if (txtView.getText().toString().trim().length() == 0) {
Toast.makeText(getApplicationContext(), "Please Enter some text to search",
Toast.Short).show();
return true; // returning true will keep the keyboard on
}
else search();
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