我有以下代码,我打算用它来查找销售和支出之间的利润:
DatabaseReference dref = FirebaseDatabase.getInstance().getReference();
DatabaseReference dreff = FirebaseDatabase.getInstance().getReference();
dref = dref.child("KatakaExpenditure");
dreff = dreff.child("KatakaSales");
dref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
int totalAmount = 0;
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
DogExpenditure dogExpenditure = postSnapshot.getValue(DogExpenditure.class);
totalAmount += dogExpenditure.getAmount();
}
textView4.setText("Your total Expenditure for Kataka Unit is:" +Integer.toString(totalAmount));
amounta = totalAmount;
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
dreff.addValueEventListener(new ValueEventListener() {
int totalAmountt = 0;
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
DogExpenditure dogExpenditure = postSnapshot.getValue(DogExpenditure.class);
totalAmountt += dogExpenditure.getAmount();
}
textView5.setText("Your total Sales for Kataka Unit is:" +Integer.toString(totalAmountt));
amountb = totalAmountt;
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
amountc = amountb - amounta;
textView3.setText("Your total Profit for Kataka Unit is:" +Integer.toString(amountc));
}
然而代码为我的 textView3.setText(" Kataka单位的总利润为:" + Integer.toString(amountc)); 行给出0值代码..关于如何计算这个数学的任何想法 amountc = amountb - amounta; ???提前谢谢你