Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling the keyboard's send button when nothing has been typed yet [Android]

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).

like image 288
Pieter888 Avatar asked May 07 '12 14:05

Pieter888


People also ask

How do I turn off edit text on Android?

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.


2 Answers

We cannot disable the action button on the android keyboard. You will have to settle with checking for empty string in editor action listener.

like image 88
Ronnie Avatar answered Oct 22 '22 13:10

Ronnie


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();
like image 25
Abdul Saleem Avatar answered Oct 22 '22 13:10

Abdul Saleem