rusty Mole rusty Mole - 24 days ago 9
Android Question

Firebase Recycler Adapter

Hi in my Firebase recycler adapter, in my fourth parameter I require a database reference however I would like to reference one child, and from the UID in that child and then reference another. Like in the screenshot below: I am trying to reference the key from "Chatmessages", and then use that to reference the keys in "Users". However how can i do this in my Recycler Adapter?

DB struc

public void loadUserList() {
FirebaseRecyclerAdapter<User, UserViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<User, UserViewHolder>(
User.class,
R.layout.userlist_layout,
UserViewHolder.class,

users // ref
)

Answer Source

You should use FirebaseIndexRecyclerAdapter from Firebase-UI:

public void loadUserList() {
    String chatMessageId = "5kA...LT2";    // Get or pass this key somehow
    DatabaseReference userKeyRef = rootRef.child("Chatmessages").child(chatMessageId);
    DatabaseReference userRef = rootRef.child("Users");
    FirebaseIndexRecyclerAdapter<User, UserViewHolder> firebaseRecyclerAdapter = new FirebaseIndexRecyclerAdapter<User, UserViewHolder>(
            User.class,
            R.layout.userlist_layout,
            UserViewHolder.class,
            userKeyRef,
            userRef
    )