-3

HEre's my data tree:

"look-twopointo": {
"0" {
    "comment": "Hi"
    "Text1": "Hello"
    "Text2": "Bonsoir"
    "type": "Bonjour"
    "version": "4.0.6"
}
}

For some reason querying doesn't work.

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);
        }

I don't know if it's because I'm using my phone and haven't downloaded and tried it on an emulator. Is there something I have to setup so that I can query on my phone? I actually couldn't find an error. It outputs null for NO REASON

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Jose Salgado
  • 29
  • 1
  • 6

1 Answers1

0

You need to use orderByChild() with equalTo():

Query query = mDatabase.orderByChild("version").equalTo("4.0.6");

from the docs:

public Query orderByChild (String path)

Create a query in which child nodes are ordered by the values of the specified path.

Community
  • 1
  • 1
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134