是我的数据树:
"look-twopointo": {
"0" {
"comment": "Hi"
"Text1": "Hello"
"Text2": "Bonsoir"
"type": "Bonjour"
"version": "4.0.6"
}
}
由于某些原因,查询无效。
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mDatabase = FirebaseDatabase.getInstance().getReference().child("0");// pay attention to the this path reference
// Read from the database
Query query = mDatabase.child("version")/*.orderByChild("Text1")*/.equalTo("4.0.6")/*.startAt("d")/*.endAt("Dude")*/;
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
//String value = dataSnapshot.getValue(String.class); //these three lines below are probably the problem
String value = (String) dataSnapshot.getValue();
System.out.println(value);
Text.setText(value);
}
我不知道是不是因为我正在使用手机并且没有下载并在模拟器上试过它。有什么我必须设置,以便我可以在我的手机上查询?我实际上找不到错误。它为NO REASON输出null
答案 0 :(得分:0)
您需要将orderByChild()
与equalTo()
:
Query query = mDatabase.orderByChild("version").equalTo("4.0.6");
来自文档:
public Query orderByChild (String path)
创建一个查询,其中子节点按指定路径的值排序。