简体   繁体   中英

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?

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

 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. 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 . It's not perfect, since you won't be using Firebase-UI library but it will do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM