2

String I am getting from snapshot.getKey(); is different from any other String, although I am not doing push() if i virtually compare the values of my mAuth.getUid(); string and snapshot.getKey(); they both are same, but programmatically it is not showing. I tried concatinating my snapshot.getKey(); string in textView.setText(snapshot.getKey();); also but nothing is shown in the screen.

Please note I am not posting my whole Fragment code.

In the code below the if statement is not getting true value.

FirebaseUser mAuth = FirebaseAuth.getInstance().getCurrentUser();

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference databaseReference = database.getReference();
DatabaseReference userref = databaseReference.child("Votes").child("Chat");    

final HashMap<String, String> hash = new HashMap<>();

    likeButton = (ImageView) view.findViewById(R.id.heartImage);

    likeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hash.put("chatVoteLike", "Yes, I would like it");
            userref.child(mAuth.getUid()).setValue(hash);
            likeButton.setImageResource(R.drawable.red_heart);
        }
    });


    userref.orderByKey().addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot snapshot : dataSnapshot.getChildren()){

               String uID = snapshot.getKey();
                Log.i("uId from", "firebase ---" + uID);

              if (uID == mAuth.getUid()){
                  likeButton.setImageResource(R.drawable.red_heart);
              }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

my database structure image below

kvadityaaz
  • 1,441
  • 1
  • 16
  • 23

1 Answers1

3

The problem is Solved using using uID.equals(mAuth.getUid()) instead of uID == mAuth.getUid()

kvadityaaz
  • 1,441
  • 1
  • 16
  • 23