我有一个带有 FirebaseRecyclerAdapter 的回收者视图和一个微调器。
它在活动中显示了一个对象列表,用于检索文件数据库。 我的问题是:当用户在微调器中选择值时,在回收器视图中使用过滤器的哪种更好的方法? 在下面的微调器中选择一个值时,没有任何反应......不更新RecyclerView
例如:当用户选择' Brazil'在微调器中,调用一个现有的查询
query = databaseReference.child("People").orderByChild("country").equalTo("Brazil").getRef()
; //我还不知道这是否有效。
query = databaseReference.child("People").getRef();
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
spinnerFilter = (Spinner) findViewById(R.id.spinFilter);
// - SPINNER EVENT SELECT -
AdapterView.OnItemSelectedListener selectedListener = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> spinner, View container, int position, long id)
{
if(id == 0)
{
query = databaseReference.child("PeopleList").orderByChild("country").equalTo("Canada").getRef();
}else
if(id == 1)
{
query = databaseReference.child("PeopleList").orderByChild("country").equalTo("Brazil").getRef();
}else
if(id == 2)
{
query = databaseReference.child("PeopleList").orderByChild("country").equalTo("EUA").getRef();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
query = databaseReference.child("PeopleList").getRef();
}
};
spinnerFilter.setOnItemSelectedListener(selectedListener);
// --- RECYCLER VIEW ----
if (mRecyclerView != null) {
mRecyclerView.setHasFixedSize(true);
}
gLayoutManager= new GridLayoutManager(this, 2);
mRecyclerView.setLayoutManager(gLayoutManager);
FirebaseRecyclerAdapter<People, PeopleListViewHolder> adapter = new FirebaseRecyclerAdapter<People, PeopleListViewHolder>
(
People.class,
R.layout.layout_people_item,
PeopleListViewHolder.class,
query
)
{
@Override
protected void populateViewHolder(PeopleListViewHolder viewHolder, People model, int position)
{
viewHolder.tvName.setText(model.getName());
Picasso.with(PeopleListActivity.this).load(model.getUrlThumbnail()).into(viewHolder.thumbnail);
}
};
mRecyclerView.setAdapter(adapter);
我在这里检查了很多链接但没有成功:
https://stackoverflow.com/questions/39076702/filtering-data-before-populating-view-from-firebaserecycleradapter?rq=1
https://github.com/firebase/FirebaseUI-Android/issues/15
https://groups.google.com/forum/#!topic/firebase-talk/O1kJ4VLUg10
https://github.com/firebase/FirebaseUI-Android/issues/15