I am fetching data from my database based on the userId
then I insert the data in a listview
and show it through a dialog.
The behavior I was w
Problem solved. the reason was that the if statement is adding the entire data in swapdetails object if it found a user ID then it found another one and added all of them again etc.
so just I have created bloolean inside the if statement and make it take true if it found swaper ID and then use the adapter outside the scope of the addChildEventListene.
shiftSwapDb.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.exists()) {
SwapDetails swapDetails = dataSnapshot.getValue(SwapDetails.class);
if (swapDetails.getSwapperID().equals(fromID)) {
hasSwaperID = true;
}
}
}
shiftProfileAdapter.add(swapDetails);
try this
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.exists()) {
SwapDetails swapDetails = dataSnapshot.getValue(SwapDetails.class);
if (swapDetails.getSwapperID().equals(fromID)) {
swapBodyList.add(swapDetails);
shiftProfileAdapter.notifyItemInserted(swapBodyList.length - 1);
}
}
}