This's my code, i don't know why the loop finished, then addListenerForSingleValueEvent start excute, what did i do wrong???
firebase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot itemDataSnapshot : dataSnapshot.getChildren()) {
fb.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot xdataSnapshot) {
Toast.makeText(getApplicationContext(), "YYYYYYY", Toast.LENGTH_LONG).show();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
Toast.makeText(getApplicationContext(), "XXXXXX", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
The loop is 3 time and The result of above code is Toast XXXXX apear 3 time and then Toast YYYYYYY apear 3 time, why???? i want to Toast YYYYY and then Toast XXXXX and again 3 time.