【发布时间】:2018-09-05 09:20:23
【问题描述】:
在下面的函数中,CardView 必须显示分数,但它不会根据值改变(如果相等的分数是 10,如果不是分数是 1。)
但我得到的只是难度值 1
public void getOppositeUsers22(){
usersDb.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.child("post").getValue() != null) {
if (dataSnapshot.exists() && !dataSnapshot.child("connections").child("nope").hasChild(currentUId) && !dataSnapshot.child("connections").child("yeps").hasChild(currentUId) &&dataSnapshot.child("post").getValue().toString().equals(oppositeUser2)) {
String profileImageUrl = "default";
Integer score2 = 1;
if (!dataSnapshot.child("profileImageUrl").getValue().equals("default")) {
profileImageUrl = dataSnapshot.child("profileImageUrl").getValue().toString();
if (dataSnapshot.child("industry").getValue().equals(innduusry)) {
score2 = 10;
}
}
score = String.valueOf(score2);
cards item = new cards(dataSnapshot.getKey(), dataSnapshot.child("name").getValue().toString(),score, profileImageUrl);
rowItems.add(item);
arrayAdapter.notifyDataSetChanged();
}
}
}
【问题讨论】:
-
检查您的哪个 if 条件失败。
-
这个失败了—— if (dataSnapshot.child("industry").getValue().equals(innduusry)) { score2 = 10; }
-
打印
dataSnapshot.child("industry").getValue()和innduusry的值,看看是否相同 -
是的,工业和工业的值相同,但在卡片视图中只显示 1 但必须为 10,就好像等于 score2 = 10;
-
您确定
if (dataSnapshot.child("industry").getValue().equals(innduusry)条件检查失败了吗?那么这意味着dataSnapshot.child("industry").getValue()不等于innduusry
标签: android firebase-realtime-database android-cardview