Getting different String from snapshot.getKey(); and mAuth.getUid(); Without .push();
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) {
}
});
java android android-studio firebase-realtime-database
|
show 6 more comments
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) {
}
});
java android android-studio firebase-realtime-database
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 thatmAuth.getUid()
andsnapshot.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 usinguID.equals(mAuth.getUid())
instead ofuID == mAuth.getUid()
– Jantzilla
Nov 20 '18 at 0:27
|
show 6 more comments
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) {
}
});
java android android-studio firebase-realtime-database
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) {
}
});
java android android-studio firebase-realtime-database
java android android-studio firebase-realtime-database
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 thatmAuth.getUid()
andsnapshot.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 usinguID.equals(mAuth.getUid())
instead ofuID == mAuth.getUid()
– Jantzilla
Nov 20 '18 at 0:27
|
show 6 more comments
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 thatmAuth.getUid()
andsnapshot.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 usinguID.equals(mAuth.getUid())
instead ofuID == 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
|
show 6 more comments
1 Answer
1
active
oldest
votes
The problem is Solved using using uID.equals(mAuth.getUid())
instead of uID == mAuth.getUid()
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
The problem is Solved using using uID.equals(mAuth.getUid())
instead of uID == mAuth.getUid()
add a comment |
The problem is Solved using using uID.equals(mAuth.getUid())
instead of uID == mAuth.getUid()
add a comment |
The problem is Solved using using uID.equals(mAuth.getUid())
instead of uID == mAuth.getUid()
The problem is Solved using using uID.equals(mAuth.getUid())
instead of uID == mAuth.getUid()
answered Nov 20 '18 at 4:36
kvadityaazkvadityaaz
13416
13416
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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()
andsnapshot.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 ofuID == mAuth.getUid()
– Jantzilla
Nov 20 '18 at 0:27