这是我在Firebase上的数据 -
app-<br />
-Users<br />
+366MWex62IhUaOwbkjjGedIgLQJ3<br />
-sfsfaegaergg<br />
firstname: "John"<br />
lastname: "Doe"<br />
phone: "+1123456789"<br />
我的数据库中有两个用户。我的输入是phone = "+1123456789" (2nd user)<br />
这是我的代码 -
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference(); DatabaseReference rf = rootRef.child("Users"); com.google.firebase.database.Query query = rf.orderByChild("phone").equalTo("+1123456789"); query.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for(DataSnapshot snap: dataSnapshot.getChildren()) { Log.v("children", snap.getChildren().toString()); } } @Override public void onCancelled(DatabaseError databaseError) { } });
我没有收到第二个用户的详细信息。调试器一直运行到addValueListener,然后直接退出。我需要在哪里进行更正?谢谢。
答案 0 :(得分:2)
&#34;调试器一直运行到addValueListener,然后直接退出&#34; - 结果将异步返回。你在onDataChange中设置了断点吗? - John O&#39; Reilly
谢谢。
答案 1 :(得分:0)
mFirebaseRef = mFirebaseInstance.getReference();
DatabaseReference queryLocation =
mFirebaseRef.child("BloodGroupDetail");
Query query = queryLocation.orderByChild("bloodgroup").equalTo("B+");
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
getUpdate(dataSnapshot);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
答案 2 :(得分:0)
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference().child("Users");
rootRef.orderByChild("phone").equalTo("+1123456789").addListenerForSingleValueEvent(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//data will be available on dataSnapshot.getValue();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "getUser:onCancelled", databaseError.toException());
}
});