卡内功能查看Android

时间:2018-09-05 09:20:24

标签: android firebase-realtime-database android-cardview

在下面的功能中,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();
                    }
                }
            }

2 个答案:

答案 0 :(得分:0)

解决方案:

代替:

Rectangles

写:

if (dataSnapshot.child("industry").getValue().equals(innduusry)) {
        score2 = 10;
}

然后尝试。希望它能起作用。

答案 1 :(得分:0)

此方法正在调用getOppositeUsers22()

public void checkUser(){
        final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        DatabaseReference userDb = usersDb.child(user.getUid());
        userDb.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (dataSnapshot.exists()){
                    if (dataSnapshot.child("post").getValue() != null){
                        innduusry = dataSnapshot.child("industry").getValue().toString();

                        oppositeUser2 = "post";


                        getOppositeUsers22();
                    }
                }
            }
            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }
相关问题