I have a fragment that implements SearchView.OnQueryTextListener
inside a viewPager. the onQueryTextChange
is correctly called each time the search text changes (I can log it it works fine). The problem is that when I try to call a public function of my RecyclerView adapter like :
@Override
public boolean onQueryTextChange(String newText) {
Log.i("", "search newText " + newText);
if(mMembersRecyclerAdapter!=null){
mMembersRecyclerAdapter.filterSearch(newText);
}
//((MembersRecyclerAdapter) mRecyclerView.getAdapter()).filterSearch(newText);
return true;
}
It's always null, even when my adapter is definitly not null as my RecyclerView is working correctly... Same thing for my mRecyclerView, always null..
I'm not sure what part of my code would be usful to be displayed in this topic. Feed free to ask me what you would like to see.
-- Edit, the way I add my Listener, it's obviously not optimal, maybe the issue comes from there :
In the activity that contains the view pager that contains the fragment :
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
switch (mFragmentSelected){
case PAGE_MEMBERS:
getMenuInflater().inflate(R.menu.main_pager_member_page, menu);
MenuItem searchItem = menu.findItem(R.id.search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnQueryTextListener((MainPagerMembersFragment) mViewPagerAdapter.getItem(PAGE_MEMBERS));
break;
default:
getMenuInflater().inflate(R.menu.main_pager, menu);
break;
}
return true;
}
Thanks,