SearchView's OnCloseListener doesn't work

前端 未结 18 2497
有刺的猬
有刺的猬 2020-11-27 02:44

I\'m trying to add support for the SearchView in the Android 3.0+ ActionBar, but I can\'t get the OnCloseListener to work.

Here\'s my code:

18条回答
  •  眼角桃花
    2020-11-27 03:14

    It's a workaround but has worked for me

      searchView.setOnQueryTextListener(new android.widget.SearchView.OnQueryTextListener() {
    
                    String lastText;
    
                    @Override
                    public boolean onQueryTextChange(final String newText) {
                        if (lastText != null && lastText.length() > 1 && newText.isEmpty()) {
                            // close ctn clicked
    
                            return true;
                        }
    }
    

提交回复
热议问题