Reputation: 336
I try to get a value from my firebase real-time DB on my app but i can't use .getValue()
to get the value of the post likes on my activity for some reason. I have try to make another reference inside on another class but i still can't use the getValue()
method.
A part of my code:
public static void setIconToLiked(String postID) {
likeRef.addValueEventListener(new ValueEventListener() {
public ImageSwitcher like_btn;
@Override
public void onDataChange(@NonNull @NotNull DataSnapshot snapshot) {
if (snapshot.child(postID).hasChild(HomeActivity.userID)){
// user has been liked this so we need to change the icon of the button to liked \\
like_btn.setImageResource(R.drawable.like_emoji);
// here i can't get the value of the post likes \\
postRef.child(postID).child("likes").getValue().toString();
}else{
// user has not liked this post so we need to set the icon of the button to not-liked \\
like_btn.setImageResource(R.drawable.like_emoji_before);
}
}
@Override
public void onCancelled(@NonNull @NotNull DatabaseError error) {
}
});
}
Upvotes: 1
Views: 49
Reputation: 336
You can use getValue
method only on an database reference
object
Upvotes: 2