Getting different String from snapshot.getKey(); and mAuth.getUid(); Without .push();












0















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










share|improve this question

























  • Please add your database structure.

    – Alex Mamo
    Nov 19 '18 at 19:30











  • added the screenshot

    – kvadityaaz
    Nov 19 '18 at 19:48











  • So you basically say that mAuth.getUid() and snapshot.getKey() return different result, right?

    – Alex Mamo
    Nov 19 '18 at 19:50











  • Yes, virtually the results are same but Programmatically they are different, although both are String .

    – kvadityaaz
    Nov 19 '18 at 19:56








  • 1





    Try using uID.equals(mAuth.getUid()) instead of uID == mAuth.getUid()

    – Jantzilla
    Nov 20 '18 at 0:27
















0















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










share|improve this question

























  • Please add your database structure.

    – Alex Mamo
    Nov 19 '18 at 19:30











  • added the screenshot

    – kvadityaaz
    Nov 19 '18 at 19:48











  • So you basically say that mAuth.getUid() and snapshot.getKey() return different result, right?

    – Alex Mamo
    Nov 19 '18 at 19:50











  • Yes, virtually the results are same but Programmatically they are different, although both are String .

    – kvadityaaz
    Nov 19 '18 at 19:56








  • 1





    Try using uID.equals(mAuth.getUid()) instead of uID == mAuth.getUid()

    – Jantzilla
    Nov 20 '18 at 0:27














0












0








0








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










share|improve this question
















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







java android android-studio firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 19:47







kvadityaaz

















asked Nov 19 '18 at 19:25









kvadityaazkvadityaaz

13416




13416













  • Please add your database structure.

    – Alex Mamo
    Nov 19 '18 at 19:30











  • added the screenshot

    – kvadityaaz
    Nov 19 '18 at 19:48











  • So you basically say that mAuth.getUid() and snapshot.getKey() return different result, right?

    – Alex Mamo
    Nov 19 '18 at 19:50











  • Yes, virtually the results are same but Programmatically they are different, although both are String .

    – kvadityaaz
    Nov 19 '18 at 19:56








  • 1





    Try using uID.equals(mAuth.getUid()) instead of uID == mAuth.getUid()

    – Jantzilla
    Nov 20 '18 at 0:27



















  • Please add your database structure.

    – Alex Mamo
    Nov 19 '18 at 19:30











  • added the screenshot

    – kvadityaaz
    Nov 19 '18 at 19:48











  • So you basically say that mAuth.getUid() and snapshot.getKey() return different result, right?

    – Alex Mamo
    Nov 19 '18 at 19:50











  • Yes, virtually the results are same but Programmatically they are different, although both are String .

    – kvadityaaz
    Nov 19 '18 at 19:56








  • 1





    Try using uID.equals(mAuth.getUid()) instead of uID == mAuth.getUid()

    – Jantzilla
    Nov 20 '18 at 0:27

















Please add your database structure.

– Alex Mamo
Nov 19 '18 at 19:30





Please add your database structure.

– Alex Mamo
Nov 19 '18 at 19:30













added the screenshot

– kvadityaaz
Nov 19 '18 at 19:48





added the screenshot

– kvadityaaz
Nov 19 '18 at 19:48













So you basically say that mAuth.getUid() and snapshot.getKey() return different result, right?

– Alex Mamo
Nov 19 '18 at 19:50





So you basically say that mAuth.getUid() and snapshot.getKey() return different result, right?

– Alex Mamo
Nov 19 '18 at 19:50













Yes, virtually the results are same but Programmatically they are different, although both are String .

– kvadityaaz
Nov 19 '18 at 19:56







Yes, virtually the results are same but Programmatically they are different, although both are String .

– kvadityaaz
Nov 19 '18 at 19:56






1




1





Try using uID.equals(mAuth.getUid()) instead of uID == mAuth.getUid()

– Jantzilla
Nov 20 '18 at 0:27





Try using uID.equals(mAuth.getUid()) instead of uID == mAuth.getUid()

– Jantzilla
Nov 20 '18 at 0:27












1 Answer
1






active

oldest

votes


















1














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






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381329%2fgetting-different-string-from-snapshot-getkey-and-mauth-getuid-without-pu%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














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






    share|improve this answer




























      1














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






      share|improve this answer


























        1












        1








        1







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






        share|improve this answer













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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 4:36









        kvadityaazkvadityaaz

        13416




        13416
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381329%2fgetting-different-string-from-snapshot-getkey-and-mauth-getuid-without-pu%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()