Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle back button of Search View in android

SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(Menus.SEARCH));
searchView.setQueryHint(this.getString(R.string.search));
editSearch = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
editSearch.setHintTextColor(getResources().getColor(R.color.white));
searchView.setOnQueryTextListener(OnQuerySearchView);


private OnQueryTextListener OnQuerySearchView = new OnQueryTextListener() {

    @Override
    public boolean onQueryTextSubmit(String newText) {
        if (TextUtils.isEmpty(newText)) {
            listAllContact.clearTextFilter();
        } else {
            listAllContact.setFilterText(newText.toString());
        }
        return true;
    }

    @Override
    public boolean onQueryTextChange(String newText) {
        String text = editSearch.getText().toString()
                .toLowerCase(Locale.getDefault());
        adapter.filter(text);
        return true;
    }

};
like image 569
deepika taywade Avatar asked Sep 15 '14 07:09

deepika taywade


1 Answers

MenuItemCompat.setOnActionExpandListener is now deprecated

use

menu.findItem(R.id.action_search)setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
    @Override
    public boolean onMenuItemActionExpand(MenuItem menuItem) {
        return false;
    }

    @Override
    public boolean onMenuItemActionCollapse(MenuItem menuItem) {
        return false;
    }
});

instead

like image 62
Mohhamed Nabil Avatar answered Sep 23 '22 08:09

Mohhamed Nabil