Issue
I have a regular RecyclerView in FRA I set up in onbindviewholder class. İt turns longth as you see in app there is a space for all items normally I should see there reply text but just one can see.
dbreply.child(post_key).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot ds:snapshot.getChildren()) {
for (DataSnapshot snapshot1:ds.getChildren()) {
reply data = snapshot1.getValue(reply.class);
list.add(data);
holder.rcv.setLayoutManager(new LinearLayoutManager(getContext()));
myAdapter = new MyAdapter(getContext(), list);
holder.rcv.setAdapter(myAdapter);
myAdapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) { }});
Solution
You are getting that behavior because you are creating a new instance of MyAdapter at each iteration of the inner loop. What you should is to get all those 4 lines of code out of the loop, as you can see below:
for (DataSnapshot ds:snapshot.getChildren()) {
for (DataSnapshot snapshot1:ds.getChildren()) {
reply data = snapshot1.getValue(reply.class);
list.add(data);
}
holder.rcv.setLayoutManager(new LinearLayoutManager(getContext()));
myAdapter = new MyAdapter(getContext(), list);
holder.rcv.setAdapter(myAdapter);
myAdapter.notifyDataSetChanged();
}
Answered By - Alex Mamo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.