SearchView with multiple fragments using viewpager in android

前端 未结 3 1849
死守一世寂寞
死守一世寂寞 2021-02-02 16:06

I want to implement SearchView with multiple fragments present in a viewPager. All fragemnts contains lists and I want to filter those lists and create a new ListView which has

3条回答
  •  無奈伤痛
    2021-02-02 16:59

    I got my fragments have list with one Searchview working by using following code.. Place the code in each fragment where you want to

     @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
    
        if (isVisibleToUser)
        {
           search_bar.setOnQueryTextListener(this);
            if(listAdapter!=null)
                listAdapter.getFilter().filter(search_bar.getQuery());
        }
    }
    

    Screenshots:

提交回复
热议问题