I'm listing Firebase data in a RecyclerView
, but when adding data or removing, the data repeats in the list. I used clear();
or lista.removeAll(lista);
to clear before filling only that the list is updated and returns the scroll position to the beginning. Does anyone have an idea how to avoid this?
Here's my code:
ValueEventListener listener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//
Escala.removeAll(Escala);
for (DataSnapshot singleSnapshot : dataSnapshot.getChildren()){
ModelEscala model = singleSnapshot.getValue(ModelEscala.class);
Escala.add(model);
recyclerViewAdapterEscalas = new RecyclerViewAdapterEscalas(getActivity(), Escala, mImageLoader);
recyclerViewAdapterEscalas.notifyDataSetChanged();
recyclerView.setAdapter(recyclerViewAdapterEscalas);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
mDataBase.addValueEventListener(listener);