Is there any listener on Android SearchView to notify if SearchView is expanded and ready to take input?

前端 未结 4 1569
攒了一身酷
攒了一身酷 2021-02-13 11:10

I want to show some default suggestions in SearchView when User hasn\'t typed anything. I am setting my custom suggestion adapter manually using matrix cursor. I tried setting

4条回答
  •  醉酒成梦
    2021-02-13 11:50

     @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.main, menu);
            vwSearch = (SearchView) menu.findItem(R.id.menu_main_search).getActionView();
            vwSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                     //Do something on Submit
                    return false;
                }
    
                @Override
                public boolean onQueryTextChange(String newText) {
                     //Do something on change
                    return true;
                }
    
    
            });
    
            vwSearch.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    //Do something on collapse Searchview
                    return false;
                }
            });
    
            return true;
        }
    

提交回复
热议问题