Firebase Android Java - Can't get value of a childIs Java “pass-by-reference” or “pass-by-value”?Does a finally block always get executed in Java?How to get an enum value from a string value in Java?Does Java support default parameter values?Get current stack trace in JavaHow do I determine whether an array contains a particular value in Java?Static way to get 'Context' in Android?Get current time and date on AndroidCan't start Eclipse - Java was started but returned exit code=13Adding Social Media Share Logic From Firebase in Android
What would a biological creature need in order to see into the future?
What's the difference between a share and a stock?
First Number to Contain Each Letter
If magnetic force can't do any work, then how can we define a potential?
Tying double knot of garbarge bag
How do I stop making people jump at home and at work?
Is there any difference between these two sentences? (Adverbs)
MOSFET broke after attaching capacitor bank
What's the point of this macro?
How do I anonymously report the Establishment Clause being broken?
My Friend James
Why does the seven segment display have decimal point at the right?
GFI outlets tripped after power outage
Global variables and information security
What fraction of 2x2 USA call signs are vanity calls?
Why are all volatile liquids combustible
Is it possible to observe space debris with Binoculars?
Do 643,000 Americans go bankrupt every year due to medical bills?
How do I make my fill-in-the-blank exercise more obvious?
What's this constructed number's starter?
Where on Earth is it easiest to survive in the wilderness?
Dissuading my girlfriend from a scam
Why do old games use flashing as means of showing damage?
A Meal fit for a King
Firebase Android Java - Can't get value of a child
Is Java “pass-by-reference” or “pass-by-value”?Does a finally block always get executed in Java?How to get an enum value from a string value in Java?Does Java support default parameter values?Get current stack trace in JavaHow do I determine whether an array contains a particular value in Java?Static way to get 'Context' in Android?Get current time and date on AndroidCan't start Eclipse - Java was started but returned exit code=13Adding Social Media Share Logic From Firebase in Android
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
So I have been trying to implement a way to check if the user had already sent a friend a request to the profile visited, or if the user has received a friend request from the profile visited. Based on the results, the buttons will be set to sent request
, accept request
,add friend
or friends
However, in my Firebase function, the first 3 if
statements aren't met, even if one of them was supposed to be met. The first else if
statement should have worked because I already sent a friend request to the profile visited.
When I ran a debug, it shows something like value = sentFriendRequests=jmarston=2
. So Firebase knows that I added John Marston as a friend, but for some reason the else if
statement wasn't working. Its the else
statement that works instead
My code is down below:
checkFriendRequestStatus function
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID)
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 1);
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 2);
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 3);
else
buttonsCallback.setButtonStatus(1, 4);;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
onViewCreated function
@Override
public void onViewCreated(View view, Bundle savedInstanceState)
sRFullName = (TextView) view.findViewById(R.id.sRUFullNameET);
addFriendBtn = (Button) view.findViewById(R.id.sRUAddFriendBtn);
sentRequestBtn = (Button) view.findViewById(R.id.sRUFriendReqSentBtn);
acceptRequestBtn = (Button) view.findViewById(R.id.sRUAcceptRequestBtn);
wereFriendsBtn = (Button) view.findViewById(R.id.sRUWeFriendsBtn);
final String strVisitedUserID = getArguments().getString("sRUserID");
final String visitedUsername = getArguments().getString("sRUsername");
ShPreference = getActivity().getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
// converts Stringed userID back to Int
final String strSignedInUID = ShPreference.getInt(currentUserID, 0) + "";
final String signedInUsername = ShPreference.getString(currentUsername, "");
// converts the userSignedIn id to string
//final String strSignedInUID = userSignedInID + "";
// checks if the current User visited has been sent a friend Request
checkFriendRequestStatus(new ButtonStatus()
@Override
public void setButtonStatus(int choice, int button)
/**
* The choice params is for the choose if to show or hide buttons.
* The buttons params selects which buttons are to show or hide
*/
addFriendBtn.setVisibility(View.GONE);
sentRequestBtn.setVisibility(View.GONE);
acceptRequestBtn.setVisibility(View.GONE);
wereFriendsBtn.setVisibility(View.GONE);
// if choosed to show buttons
if (choice == 1)
// show buttons depending on the friendRequest status
if (button == 1)
wereFriendsBtn.setVisibility(View.VISIBLE);
else if (button == 2)
sentRequestBtn.setVisibility(View.VISIBLE);
else if (button == 3)
acceptRequestBtn.setVisibility(View.VISIBLE);
else
addFriendBtn.setVisibility(View.VISIBLE);
, strSignedInUID, visitedUsername, strVisitedUserID);
// sets the name with the Full Name; called from SearchResultsAdapter
sRFullName.setText(getArguments().getString("sRFullName"));
java android firebase firebase-realtime-database
add a comment |
So I have been trying to implement a way to check if the user had already sent a friend a request to the profile visited, or if the user has received a friend request from the profile visited. Based on the results, the buttons will be set to sent request
, accept request
,add friend
or friends
However, in my Firebase function, the first 3 if
statements aren't met, even if one of them was supposed to be met. The first else if
statement should have worked because I already sent a friend request to the profile visited.
When I ran a debug, it shows something like value = sentFriendRequests=jmarston=2
. So Firebase knows that I added John Marston as a friend, but for some reason the else if
statement wasn't working. Its the else
statement that works instead
My code is down below:
checkFriendRequestStatus function
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID)
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 1);
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 2);
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 3);
else
buttonsCallback.setButtonStatus(1, 4);;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
onViewCreated function
@Override
public void onViewCreated(View view, Bundle savedInstanceState)
sRFullName = (TextView) view.findViewById(R.id.sRUFullNameET);
addFriendBtn = (Button) view.findViewById(R.id.sRUAddFriendBtn);
sentRequestBtn = (Button) view.findViewById(R.id.sRUFriendReqSentBtn);
acceptRequestBtn = (Button) view.findViewById(R.id.sRUAcceptRequestBtn);
wereFriendsBtn = (Button) view.findViewById(R.id.sRUWeFriendsBtn);
final String strVisitedUserID = getArguments().getString("sRUserID");
final String visitedUsername = getArguments().getString("sRUsername");
ShPreference = getActivity().getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
// converts Stringed userID back to Int
final String strSignedInUID = ShPreference.getInt(currentUserID, 0) + "";
final String signedInUsername = ShPreference.getString(currentUsername, "");
// converts the userSignedIn id to string
//final String strSignedInUID = userSignedInID + "";
// checks if the current User visited has been sent a friend Request
checkFriendRequestStatus(new ButtonStatus()
@Override
public void setButtonStatus(int choice, int button)
/**
* The choice params is for the choose if to show or hide buttons.
* The buttons params selects which buttons are to show or hide
*/
addFriendBtn.setVisibility(View.GONE);
sentRequestBtn.setVisibility(View.GONE);
acceptRequestBtn.setVisibility(View.GONE);
wereFriendsBtn.setVisibility(View.GONE);
// if choosed to show buttons
if (choice == 1)
// show buttons depending on the friendRequest status
if (button == 1)
wereFriendsBtn.setVisibility(View.VISIBLE);
else if (button == 2)
sentRequestBtn.setVisibility(View.VISIBLE);
else if (button == 3)
acceptRequestBtn.setVisibility(View.VISIBLE);
else
addFriendBtn.setVisibility(View.VISIBLE);
, strSignedInUID, visitedUsername, strVisitedUserID);
// sets the name with the Full Name; called from SearchResultsAdapter
sRFullName.setText(getArguments().getString("sRFullName"));
java android firebase firebase-realtime-database
add a comment |
So I have been trying to implement a way to check if the user had already sent a friend a request to the profile visited, or if the user has received a friend request from the profile visited. Based on the results, the buttons will be set to sent request
, accept request
,add friend
or friends
However, in my Firebase function, the first 3 if
statements aren't met, even if one of them was supposed to be met. The first else if
statement should have worked because I already sent a friend request to the profile visited.
When I ran a debug, it shows something like value = sentFriendRequests=jmarston=2
. So Firebase knows that I added John Marston as a friend, but for some reason the else if
statement wasn't working. Its the else
statement that works instead
My code is down below:
checkFriendRequestStatus function
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID)
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 1);
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 2);
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 3);
else
buttonsCallback.setButtonStatus(1, 4);;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
onViewCreated function
@Override
public void onViewCreated(View view, Bundle savedInstanceState)
sRFullName = (TextView) view.findViewById(R.id.sRUFullNameET);
addFriendBtn = (Button) view.findViewById(R.id.sRUAddFriendBtn);
sentRequestBtn = (Button) view.findViewById(R.id.sRUFriendReqSentBtn);
acceptRequestBtn = (Button) view.findViewById(R.id.sRUAcceptRequestBtn);
wereFriendsBtn = (Button) view.findViewById(R.id.sRUWeFriendsBtn);
final String strVisitedUserID = getArguments().getString("sRUserID");
final String visitedUsername = getArguments().getString("sRUsername");
ShPreference = getActivity().getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
// converts Stringed userID back to Int
final String strSignedInUID = ShPreference.getInt(currentUserID, 0) + "";
final String signedInUsername = ShPreference.getString(currentUsername, "");
// converts the userSignedIn id to string
//final String strSignedInUID = userSignedInID + "";
// checks if the current User visited has been sent a friend Request
checkFriendRequestStatus(new ButtonStatus()
@Override
public void setButtonStatus(int choice, int button)
/**
* The choice params is for the choose if to show or hide buttons.
* The buttons params selects which buttons are to show or hide
*/
addFriendBtn.setVisibility(View.GONE);
sentRequestBtn.setVisibility(View.GONE);
acceptRequestBtn.setVisibility(View.GONE);
wereFriendsBtn.setVisibility(View.GONE);
// if choosed to show buttons
if (choice == 1)
// show buttons depending on the friendRequest status
if (button == 1)
wereFriendsBtn.setVisibility(View.VISIBLE);
else if (button == 2)
sentRequestBtn.setVisibility(View.VISIBLE);
else if (button == 3)
acceptRequestBtn.setVisibility(View.VISIBLE);
else
addFriendBtn.setVisibility(View.VISIBLE);
, strSignedInUID, visitedUsername, strVisitedUserID);
// sets the name with the Full Name; called from SearchResultsAdapter
sRFullName.setText(getArguments().getString("sRFullName"));
java android firebase firebase-realtime-database
So I have been trying to implement a way to check if the user had already sent a friend a request to the profile visited, or if the user has received a friend request from the profile visited. Based on the results, the buttons will be set to sent request
, accept request
,add friend
or friends
However, in my Firebase function, the first 3 if
statements aren't met, even if one of them was supposed to be met. The first else if
statement should have worked because I already sent a friend request to the profile visited.
When I ran a debug, it shows something like value = sentFriendRequests=jmarston=2
. So Firebase knows that I added John Marston as a friend, but for some reason the else if
statement wasn't working. Its the else
statement that works instead
My code is down below:
checkFriendRequestStatus function
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID)
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 1);
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 2);
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class) == strVisitedUID)
buttonsCallback.setButtonStatus(1, 3);
else
buttonsCallback.setButtonStatus(1, 4);;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
onViewCreated function
@Override
public void onViewCreated(View view, Bundle savedInstanceState)
sRFullName = (TextView) view.findViewById(R.id.sRUFullNameET);
addFriendBtn = (Button) view.findViewById(R.id.sRUAddFriendBtn);
sentRequestBtn = (Button) view.findViewById(R.id.sRUFriendReqSentBtn);
acceptRequestBtn = (Button) view.findViewById(R.id.sRUAcceptRequestBtn);
wereFriendsBtn = (Button) view.findViewById(R.id.sRUWeFriendsBtn);
final String strVisitedUserID = getArguments().getString("sRUserID");
final String visitedUsername = getArguments().getString("sRUsername");
ShPreference = getActivity().getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
// converts Stringed userID back to Int
final String strSignedInUID = ShPreference.getInt(currentUserID, 0) + "";
final String signedInUsername = ShPreference.getString(currentUsername, "");
// converts the userSignedIn id to string
//final String strSignedInUID = userSignedInID + "";
// checks if the current User visited has been sent a friend Request
checkFriendRequestStatus(new ButtonStatus()
@Override
public void setButtonStatus(int choice, int button)
/**
* The choice params is for the choose if to show or hide buttons.
* The buttons params selects which buttons are to show or hide
*/
addFriendBtn.setVisibility(View.GONE);
sentRequestBtn.setVisibility(View.GONE);
acceptRequestBtn.setVisibility(View.GONE);
wereFriendsBtn.setVisibility(View.GONE);
// if choosed to show buttons
if (choice == 1)
// show buttons depending on the friendRequest status
if (button == 1)
wereFriendsBtn.setVisibility(View.VISIBLE);
else if (button == 2)
sentRequestBtn.setVisibility(View.VISIBLE);
else if (button == 3)
acceptRequestBtn.setVisibility(View.VISIBLE);
else
addFriendBtn.setVisibility(View.VISIBLE);
, strSignedInUID, visitedUsername, strVisitedUserID);
// sets the name with the Full Name; called from SearchResultsAdapter
sRFullName.setText(getArguments().getString("sRFullName"));
java android firebase firebase-realtime-database
java android firebase firebase-realtime-database
edited Mar 28 at 9:57
KENdi
6,1222 gold badges10 silver badges22 bronze badges
6,1222 gold badges10 silver badges22 bronze badges
asked Mar 28 at 4:07
Elly RichardsonElly Richardson
888 bronze badges
888 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
To compare String object use equals instead of == (double equals). Double equals will compare reference not their values.
Update your code of comparison like below:
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID)
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 1);
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 2);
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 3);
else
buttonsCallback.setButtonStatus(1, 4);;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
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%2f55390008%2ffirebase-android-java-cant-get-value-of-a-child%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
To compare String object use equals instead of == (double equals). Double equals will compare reference not their values.
Update your code of comparison like below:
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID)
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 1);
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 2);
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 3);
else
buttonsCallback.setButtonStatus(1, 4);;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
add a comment |
To compare String object use equals instead of == (double equals). Double equals will compare reference not their values.
Update your code of comparison like below:
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID)
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 1);
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 2);
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 3);
else
buttonsCallback.setButtonStatus(1, 4);;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
add a comment |
To compare String object use equals instead of == (double equals). Double equals will compare reference not their values.
Update your code of comparison like below:
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID)
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 1);
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 2);
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 3);
else
buttonsCallback.setButtonStatus(1, 4);;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
To compare String object use equals instead of == (double equals). Double equals will compare reference not their values.
Update your code of comparison like below:
private void checkFriendRequestStatus(final ButtonStatus buttonsCallback, final String strSignedInUID, final String visitedUsername, final String strVisitedUID)
final DatabaseReference checkFriendRequestsRef = database.getReference("friend_requests/test/" + strSignedInUID);
checkFriendRequestsRef.addListenerForSingleValueEvent(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
// choice is 1 to show buttons, then select which buttons to show with second params
if (dataSnapshot.child("friends/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 1);
else if (dataSnapshot.child("sentFriendRequest/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 2);
else if (dataSnapshot.child("receivedFriendRequests/" + visitedUsername).getValue(String.class).equals(strVisitedUID))
buttonsCallback.setButtonStatus(1, 3);
else
buttonsCallback.setButtonStatus(1, 4);;
@Override
public void onCancelled(@NonNull DatabaseError databaseError)
);
answered Mar 28 at 4:19
Viraj PatelViraj Patel
1,2334 silver badges17 bronze badges
1,2334 silver badges17 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55390008%2ffirebase-android-java-cant-get-value-of-a-child%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