2
I am listing data from Firebase in a RecyclerView
, but when adding or removing data, the data is repeated in the list. I used the clear();
or lista.removeAll(lista);
to clear before filling only the list is updated and back scroll position to start. Does anyone have an idea how to avoid this?
Just follow 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);
Guilherme Montanher thank you so much for answering my question you are the guy solved my problem!
– Natanael Nael