1 回答

TA貢獻1895條經(jīng)驗 獲得超3個贊
您不需要嵌套的偵聽器來獲取Rabbani支出。由于此數(shù)據(jù)已存在于 中databasedeposit,因此您可以if在現(xiàn)有循環(huán)中使用 來跟蹤該數(shù)據(jù):
databasedeposit.addListenerForSingleValueEvent (new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
abc.clear();
Integer total = 0;
Integer n_total=0;
for (DataSnapshot ds : dataSnapshot.getChildren()) {
ADeposit bazar = ds.getValue(ADeposit.class);
Integer cost = Integer.valueOf(bazar.getAmount());
total = total + cost;
abc.add(bazar);
if ("Rabbani".equals(ds.child("name").getValue(String.class)) {
n_total = n_total + cost;
}
}
System.out.println("total: "+total+", n_total: "+n_total);
...
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException(); // don't ignore errors
}
}); ;
添加回答
舉報