android - How to pull specific value from firebase -
i working on app need pull specific value firebase. case need pull "score" "uid" equals current user id. best way so.
thank help.
firebase return full nodes. cannot return score user. can return common node both score , user under (the 1 starting -k...
) using firebase query:
databasereference leadersref = firebasedatabase.getinstance().getreference("leaders"); query query = leadersref.orderbychild("uid").equalto("vudnkx..."); query.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot snapshot) { (datasnapshot child: snapshot.getchildren()) { system.out.println(child.getkey()+": "+child.child("score").getvalue(long.class)); } } @override public void oncancelled(databaseerror databaseerror) { // getting post failed, log message log.w(tag, "oncancelled", databaseerror.toexception()); // ... } })
note code loops on snapshot
in result. because query potentially have multiple results. snapshot contains list of results. if there single result, snapshot contain list of 1 result.
for more reading see firebase documentation on handling lists , sorting , filtering data.
Comments
Post a Comment