when I use a ValueEventListener
inside a populateViewHolder
, the list gets empty. But when I don't, the list is filled with the place holder. It's strange because I already used that EventListener
in other recyclerview and works fine. But I don't know what happens here.
The reason of why I have to use it is be cause I have in my database something like this:
-> root
---> Events
------> -L9TDlh9MukU9vuHUAv-
----------> asist
--------------> Users ids that go to this event
----------> /* Other event stuff */
------> -LA3OyftXo2nSKMzhVCu
----------> asist
--------------> Users ids that go to this event
----------> /* Other event stuff */
---> Users
------> JrB6orsAs0PP7SHLKfiC9hEE9ax1
---------> /* User stuff */
------> MfFyQ2GbDbRr61I8j4QtQn7XoIj1
---------> /* User stuff */
So the recyclerview gets event's asist list and for every item I get the user's ids. With each id I set a ValueEventListener from Users database and there I get the user information to fill the item's stuff. I do this a lot of times and everytime works great. But I don't know why I can't fix this.
Here is the recyclerView config:
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
Here is the adapter:
userDatabase = FirebaseDatabase.getInstance().getReference().child("Events").child("-L9TDlh9MukU9vuHUAv-").child("asist");
adapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
Users.class,
R.layout.users_row_layout,
UsersViewHolder.class,
userDatabase
) {
@Override
protected void populateViewHolder(final UsersViewHolder viewHolder, Users model, final int position) {
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
mDatabase.child(getRef(position).getKey().toString()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
};
recyclerView.setAdapter(adapter);