How To Handle Back Arrow Event In A Searchview
How can I handle the click event on the back arrow in the searchview widget: I tried this code but it doesn't work: searchtollbar.setNavigationOnClickListener(new View.OnClickList
Solution 1:
To handle that you have to override onOptionsItemSelected
method.
@OverridepublicbooleanonOptionsItemSelected(MenuItem item) {
// Handle item selectionswitch (item.getItemId()) {
case android.R.id.home:
// handle back event.returntrue;
default:
returnsuper.onOptionsItemSelected(item);
}
}
Solution 2:
Try with
MenuItem item = menu.findItem(R.id.action_search);
SearchView searchView = newSearchView(((MainActivity) mContext).getSupportActionBar().getThemedContext());
item.setOnActionExpandListener(newMenuItem.OnActionExpandListener() {
@OverridepublicbooleanonMenuItemActionExpand(MenuItem menuItem) {
Log.d( TAG, "expand" );
returntrue;
}
@OverridepublicbooleanonMenuItemActionCollapse(MenuItem menuItem) {
Log.d( TAG, "collapse" );
returntrue;
}
});
Post a Comment for "How To Handle Back Arrow Event In A Searchview"