1

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);
Janvi Vyas
  • 732
  • 5
  • 16
  • Can you confirm that you are grabbing the correct data? `dataSnapshot.getValue()` should return data. Also, where are you setting the contents of `dataSnapshot.getValue()` to your `reyclerView` datasource? – Torewin May 02 '18 at 04:12
  • put a log in the response and check if the response is coming? – nimi0112 May 02 '18 at 11:51
  • **[This](https://stackoverflow.com/questions/49383687/how-can-i-retrieve-data-from-firebase-to-my-adapter/49384849)** is how you can retrieve data from a Firebase Realtime database and display it in a `RecyclerView` using `FirebaseRecyclerAdapter`. Don't forget to start listening for changes. – Alex Mamo May 02 '18 at 14:35

0 Answers0