[英]How can i fetch the same recyclerview from multiple database references
I am setting up a Firebase Reyclerview with FirebaseRecyclerAdapter, now my adapter should be fetched from two different database references and bind into the same recyclerview, does anybody know how to solve this? 我正在使用FirebaseRecyclerAdapter设置Firebase Reyclerview,现在应该从两个不同的数据库引用中获取我的适配器,并将其绑定到同一个recyclerview中,有人知道如何解决此问题吗?
I am using an interface to fetch the database references like this 我正在使用一个接口来获取这样的数据库引用
private interface CallBack{
void onCallback(String Position, String PositionTwo);
}
Then i am sending them to a function 然后我将它们发送给函数
private void loadItems(String Position, String PositionTwo) {
adapter = new FirebaseRecyclerAdapter<Foo, FooViewHolder>(
Foo.class,
R.layout.Foo_item,
FooViewHolder.class,
reference.child(Position).child(PositionTwo)
) {
@Override
protected void populateViewHolder(FooViewHolder viewHolder,
Foo model, int position) {
viewHolder.mDescription.setText(model.getDescription());
viewHolder.mName.setText(model.getName());
Picasso.get().load(model.getImage()).into(viewHolder.mImage);
}
};
My ViewHolderClass is 我的ViewHolderClass是
public class FooViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener,
{
public TextView mName;
public CircleImageView mImage;
private ItemClickListener itemClickListener;
public TextView mDescription;
public FooViewHolder(View itemView) {
super(itemView);
mImage = (CircleImageView) itemView.findViewById(R.id.mImage);
mName = (TextView) itemView.findViewById(R.id.mName);
mDescription = (TextView) itemView.findViewById(R.id.mDescription);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
}
Now this does not work as it only takes the first argument passed to the adapter but not what is passed after that from the interface! 现在这不起作用,因为它只接受传递给适配器的第一个参数,而不接受从接口传递的参数!
now my adapter should be fetched from two different database references. 现在应该从两个不同的数据库引用中获取我的适配器。
This basically means that you are trying to use two queries (database references) and pass them to an adapter but unfortunately there is no way to combine two queries in a single FirestoreRecyclerAdapter
object. 这基本上意味着您正在尝试使用两个查询(数据库引用)并将它们传递给适配器,但是不幸的是,无法在单个FirestoreRecyclerAdapter
对象中组合两个查询。 Only one is permited. 只允许一个。
A possible solution I can think of is to create a list that will contain the combined results of those queries in your app and then pass that list to an ArrayAdapter
. 我可以想到的一种可能的解决方案是创建一个列表,其中将包含您应用程序中这些查询的组合结果,然后将该列表传递给ArrayAdapter
。 It's not perfect, since you won't be using Firebase-UI
library but it will do the trick. 这不是完美的,因为您不会使用Firebase-UI
库,但是可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.