I have the following code implemented in my project:
DatabaseReference online = mPostReference.child("online").child(msg.friend_id);
online.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Online post = dataSnapshot.getValue(Online.class);
if ( viewHolder.getDiff(post.timestamp) < 1){
viewHolder.setOnline("visible");
} else {
viewHolder.setOnline("gone");
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
I have 2 items inside the recyclerview and both items have the listener attached. When data changes inside the database, the first item will return true and will show the state as online, but even the second item will be false, the icon will appear on the second item as well unless I refresh the activity by closing and reopening the app.. What I am missing here? Do I need to notify my adapter? I don't think both items goes through the if and else statements