0

我有一个键,我想检索它的值。这是我的代码:

public void afterTextChanged(Editable editable) {
    // String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
    //Query query = FirebaseDatabase.getInstance().getReference(uid).orderByChild("title").startAt(editable.toString()).endAt(editable.toString()+"\uf888");

    DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("categoreis");
    Query query =  FirebaseDatabase.getInstance().getReference("categoreis").limitToFirst(4).orderByChild("image");
    query.addValueEventListener(new ValueEventListener() {

    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        list.clear();

        for (DataSnapshot data:dataSnapshot.getChildren())
        {
            for (DataSnapshot ds:data.child("SubAccessories").getChildren())
            {
                for (DataSnapshot ds1:ds.getChildren())
                {
                    for (DataSnapshot vale:ds1.getChildren())
                    {
                        Log.d("check",vale.toString());
                        vale.getKey();`
                    }
                }
            }   
        }
    }
}
4

1 回答 1

0

假设,value 是 string 类型,key 是“myKey”

public void afterTextChanged(Editable editable) {
               // String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
                //Query query = FirebaseDatabase.getInstance().getReference(uid).orderByChild("title").startAt(editable.toString()).endAt(editable.toString()+"\uf888");

            DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("categoreis");
           Query query =  FirebaseDatabase.getInstance().getReference("categoreis").limitToFirst(4).orderByChild("image");
            query.addValueEventListener(new ValueEventListener() {

                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    list.clear();
               for (DataSnapshot data:dataSnapshot.getChildren())
               {

                   for (DataSnapshot ds:data.child("SubAccessories").getChildren())
                   {
                       for (DataSnapshot ds1:ds.getChildren())
                       {
                          for (DataSnapshot vale:ds1.getChildren())
                          {
                              Log.d("check",vale.toString());
                              String myValue=vale.child("myKey").getValue(String.class);
                          }

                       }
                   }

               }
于 2018-07-11T12:56:36.463 回答