2

I have implemented SearchView on my ListView. When i enter some text in EditText of this search widget, it filters the contents in my list. But if i close this search widget on clicking UP/home icon without clearing the text in EditText, i am still having the filtered list not the complete list.

So i need to catch the event of UP icon for SearchView to clear the text in EditText, or is there some other way for that.

enter image description here

Aleena
  • 273
  • 4
  • 12

2 Answers2

2

May be, you need to try this one instead of relying on UP icon click event.

menuItem.setOnActionExpandListener(new OnActionExpandListener()
        {

            @Override
            public boolean onMenuItemActionCollapse(MenuItem item)
            {
                // Do something when collapsed

                return true; // Return true to collapse action view
            }

            @Override
            public boolean onMenuItemActionExpand(MenuItem item)
            {
                // Do something when Expanded
                return true;
            }
        }); 
BST Kaal
  • 2,993
  • 6
  • 34
  • 52
0

This is how you do that.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()){
    // this is item ID of that back part which you want
    case android.R.id.home:
          // Control will come here when back/or app icon is pressed
    break;
    }
    return super.onOptionsItemSelected(item);
}
Techfist
  • 4,314
  • 6
  • 22
  • 32
  • Sory, but it doesn't work. I have debugged and control does not even come in `onOptionItemSelected`. May be, the **`UP`** icon associated with this `SearchView` is not as same as the used for UP navigation. – Aleena Sep 09 '14 at 06:26
  • Thnx @Techfist, found a sound solution. – Aleena Sep 09 '14 at 06:58