3

I am using the SearchView according to this guide, and I tried to collapse the searchview like this:

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        mSearchView = (SearchView) MenuItemCompat.getActionView(item);
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));


        expand = !Helper.isNullOrEmpty(placeHolder);
        Log.d("map", "set mSearch view with expand:" + expand + ", queryStr:" + placeHolder);
        if (expand) {
            MenuItemCompat.expandActionView(item);
//            mSearchView.setQuery(placeHolder, false);
        } else {
            boolean x = MenuItemCompat.collapseActionView(item);
            Log.d("map", "coop view:" + x);
        }

However I always get this:

coop view: false

What's the problem?

BTW, I am getting crazy by the internal SearchView's strange behavior. Do you guys use this or something else?


Update(Why I want to control the searchview befora manually)

The activity which hold the serchview is my core activity, that's to say most of the search related job will be passed to this activity.

User may enter the search parameter in other activity and start a new Intent to this activity to do the job, then I have to change the status of the searchview manually

Community
  • 1
  • 1
hguser
  • 35,079
  • 54
  • 159
  • 293

1 Answers1

0

This would appear to solve the issue:

How to completely collapse a SearchView after an item selected?

According to the above thread (tested ok for me), you have to do this:

MenuItemCompat.collapseActionView(searchItem);

searchView.onActionViewCollapsed();

If you're not using AppCompat library, you can do this:

searchItem.collapseActionView();

searchView.onActionViewCollapsed();
Community
  • 1
  • 1
3c71
  • 4,313
  • 31
  • 43