cavallo
cavallo

Reputation: 4414

How to clear the search result when clearing the edit text in Android?

I have a search in my app. How to clear the searched result when I clear the edit text? Even after I remove the word from the edit text, the searched result remains the same. How to implement this? Thanks for the help in advance.

Upvotes: 0

Views: 269

Answers (2)

alchemist
alchemist

Reputation: 1081

Hey buddy try the clear edit text button given here : http://mytechead.wordpress.com/2012/02/07/create-ios-like-cleartextbutton-in-android/

Upvotes: 0

Hiral Vadodaria
Hiral Vadodaria

Reputation: 19250

Try this:

etSearchText.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {        
            }
            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                            int arg3) {             
            }           
            @Override
            public void afterTextChanged(Editable arg0) {

                     String text=etSearchText.getText().toString().trim();
                     if(text.equals(""))
                     {
                           //clear the results here
                     }              
                }
});

Upvotes: 2

Related Questions