How to completely collapse a SearchView after an item selected?

后端 未结 10 1912
萌比男神i
萌比男神i 2021-01-31 17:35

I\'ve been struggling with this for weeks.. I have a global search that offers up a custom listview with suggestions as a user types. When a user selects an option, I want the s

相关标签:
10条回答
  • 2021-01-31 17:50

    I've changed the 'Go' button to 'Next', so the only method that worked for me (on API 19) is typing closeBtn.performClick(); closeBtn.performClick(); (Clicking 'close' button twice) in the OnEditorActionListener of the AutoCompleteTextView. You can get the AutoCompleteTextView like this:

    LinearLayout linearLayout1 = (LinearLayout) searchView.getChildAt(0);
    LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
    LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
    AutoCompleteTextView autoComplete = (AutoCompleteTextView) linearLayout3.getChildAt(0);
    
    0 讨论(0)
  • 2021-01-31 17:51

    @sebastian that's not actually right.

    I've been stucked at this issue for a while, but finally I've managed to handle it in the right way. You're suppose to call menuSearch.collapseActionView(); instead. This method will call onActionViewCollapsed, which you could override. So you don't call a listener ;)

    MenuItem menuSearch = menu.findItem(R.id.itemSearch);
    SearchView searchView = (SearchView) menuSearch.getActionView();
    //Don't use next line
    //searchView.onActionViewCollapsed();
    menuSearch.collapseActionView();
    
    0 讨论(0)
  • 2021-01-31 17:56

    This worked for me searchMenuItem.collapseActionView();

    0 讨论(0)
  • 2021-01-31 17:56

    Returning false should have been sufficient based on the latest documentation and the source code iff iconifiedByDefault == true.

    Did you by any chance define iconifiedByDefault="false" or called setIconifiedByDefault(false)?

    0 讨论(0)
提交回复
热议问题