简体   繁体   中英

Android Firebase - retrieve particular value from Firebase realtime database

In my application I want to retrieve a single value from a particular id. The below screenshot is my database structure:

在此处输入图片说明

I want to retrieve the count of likes from database.

This is what I have tried:

 public String getLikesCount(String USER_ID){
    mref = FirebaseDatabase.getInstance().getReference("user").child(USER_ID);
    return currentLike;
}

I don't know what to do after this to get likes count. Can anyone help me please?

do the following:

mref = FirebaseDatabase.getInstance().getReference("user").child(USER_ID).child("likes");
mref.addListenerForSingleValueEvent(new ValueEventListener() {
 @Override
 public void onDataChange(DataSnapshot dataSnapshot) {
    String likes = dataSnapshot.getValue(String.class);
    //do what you want with the likes
 }

 @Override
 public void onCancelled(DatabaseError databaseError) {

 }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM