我正在寻找一种使用searchView在RecyclerView中过滤我的数据的方法,但仍然卡住了,我读过这篇文章Filtering a recyclerview with a firebaserecycleradapter和Filter data on firebase with Searchview,但没有任何明确的答案。而且他们是唯一可用的职位。
在这个问题上也没有明确的例子。
请大家帮我解决一下使用RecyclerView
Firebase
SearchView
过滤数据的完整简单示例吗?
下面是Load()
方法ic OnCreate()
加载项目列表。
void Load(){
// mAuth.addAuthStateListener(mAuthLitsener);
FirebaseRecyclerAdapter<Event,EventViewHolder> firebaseRecyclerAdapter_ = new FirebaseRecyclerAdapter<Event, GraduationListActivity.EventViewHolder>(Event.class,
R.layout.item_event_view,
GraduationListActivity.EventViewHolder.class,
queryRef) {
@Override
protected void populateViewHolder(GraduationListActivity.EventViewHolder viewHolder, final Event model, final int position) {
final String key_post = getRef(position).getKey();
viewHolder.setEventLocation(model.getEventLocation());
viewHolder.setEventName(model.getEventName());
viewHolder.setEventType(model.getEventType());
viewHolder.setEventDate(model.getEventDate());
viewHolder.setEventPic(c, model.getEventImage());
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(EventViewActivity.this,"This is : "+position,Toast.LENGTH_LONG).show();
Intent loadMainActivity = new Intent(GraduationListActivity.this,BlogActivity.class);
loadMainActivity.putExtra("PARTY_NAME", model.getEventName());
startActivity(loadMainActivity);
}
});
}
};
mRecyclerview_event_view.setAdapter(firebaseRecyclerAdapter_);
}
这是我的onCreateOptionsMenu()
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.search, menu);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
// ????????
}
@Override
public boolean onQueryTextChange(String newText) {
//??????
return true;
}
});
return super.onCreateOptionsMenu(menu);
}
所以我使用searchView进行搜索但很困惑:根据Firebase,我应该将onQueryTextChange()
和onQueryTextSubmit()
放入什么内容?