android - collapse searchview after submit

dracula picture dracula · May 21, 2013 · Viewed 11.4k times · Source

I am using searchview in my application ( without action bar). How can i collapse searchview after query text submit ?

I have these listeners ;

        @Override
        public boolean onQueryTextSubmit(String query) {

            InputMethodManager imm = (InputMethodManager)thisFr.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(globalSearch.getWindowToken(), 0);

            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // TODO Auto-generated method stub
            return false;
        }

I don't use ActionBar so i don't have a function like collapseActionView() .

Waiting for help

Thanks

Answer

nosaiba darwish picture nosaiba darwish · May 13, 2015

you need to call setIconified(true) twice to actually collapse your search view, with first call text is cleared with second call keyboard and search view get closed.