mUserBalance.child(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int lim = 100;
//final String user_bal = String.valueOf(dataSnapshot.child("balance").getValue());
//balance from firebase database
String user_bal = (String) dataSnapshot.child("balance").getValue();
if (user_bal.){
Toast.makeText(PostActivity.this, user_bal, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(PostActivity.this, "not enough balance", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
答案 0 :(得分:0)
user_bal是String数据类型,因此< =不是首选。如果你确定这个变量的值是数字(变量lim的整数是int类型,用于比较),那么试试这个
String user_bal = (String) dataSnapshot.child("balance").getValue();
int userBalance = Integer.parseInt(user_bal);
if (userBalance <= lim){
// do something
Toast.makeText(PostActivity.this, " NOt enough balance", Toast.LENGTH_LONG).show();
}else{
// do something
Toast.makeText(PostActivity.this, user_bal, Toast.LENGTH_LONG).show()
}