简体   繁体   English

我如何从多个数据库引用中获取相同的recyclerview

[英]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.

相关问题 如何从多个 Firestore collections 获取数据到一个 RecyclerView? - How to fetch data from multiple Firestore collections into one RecyclerView? 如何从不在EOModel中的数据库表中获取行? - How can i fetch a row from a database table that is not in my EOModel? 如何从 Firebase 数据库中获取特定值(数据) - How can I fetch particular value(data) from Firebase Database 如何从 SQLite 数据库中获取特定月份的数据 - How can I fetch the data of specific month from SQLite database 如何阻止从 Firebase 数据库填充并由 FirebaseRecyclerAdapter 管理的 RecyclerView 重新创建已删除的视图? - How can I stop my RecyclerView, populated from Firebase Database and managed by FirebaseRecyclerAdapter, from recreating deleted views? 如何将 Firebase 数据库中的正确数据放入我的 RecyclerView? - How can I put correctly data from Firebase database to my RecyclerView? 从mysql数据库列接收某些数据后,如何在recyclerview中更改特定卡片的颜色 - How can I change color of specific card in recyclerview after receiving certain data from mysql database column Firebase在单个RecyclerView中显示来自多个引用的数据 - Firebase display data from multiple references in a single RecyclerView 如何每秒使用 RecyclerView 刷新 Firebase 数据库数据 - How can I refresh Firebase database data with RecyclerView every seconde 如何使用 AsyncTask、RecyclerView 和 RecyclerView.Adapter 将手机中的图像获取到 RecyclerView? - How can I use AsyncTask, RecyclerView, and a RecyclerView.Adapter to get images from my phone into my RecyclerView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM