Fragment replacement triggers onQueryTextChange on searchview

前端 未结 7 778
臣服心动
臣服心动 2021-01-07 17:54

This is how I navigate through my app:

  • Open fragment with list
  • Filter list by a text entered in searchview
  • Tap on listitem (list fragment get
7条回答
  •  走了就别回头了
    2021-01-07 18:42

    I see you didn't find a solution yet, I have same problem posted here:

    I found that when invalidateOptionsMenu is called also the method onQueryTextChange is called because the View launch dispatchRestoreInstanceState with the previous value after you've cleared the search for example. Do you call invalidateOptionsMenu maybe?

    Maybe, inside onQueryTextChange, you can check a boolean on some current state of your application objects to know if the method content should be executed. In my case I use mDrawerLayout.isDrawerOpen(..) to allow the search.

    Also you can implement the SearchView.OnQueryTextListener on each Class you use, on a Fragment or on the Main Activity class, somewhere in the class you could set a boolean module variable that you will check inside onQueryTextChange.

提交回复
热议问题