Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        上个月关闭。
                                                                                            
                
        
我有这样的实时数据库。 Users => UID => Medicines => Date => Medicine Name:值

我有一个微调器

 ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arrayList);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    spinner.setAdapter(arrayAdapter);


我尝试了这个:

mUserDatabase=FirebaseDatabase.getInstance().getReference().child("Users").child(uid).child("Medical");


    // GET ALL DATES // GET ALL MEDICINE NAME // GET ALL Values //
    mUserDatabase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            Log.v("DATES : ",""+ dataSnapshot.getKey());

            for (DataSnapshot childDataSnapshot : dataSnapshot.getChildren()) {

                Log.v("Medicine Name",""+ childDataSnapshot.getKey());

                arraList.add(childDataSnapshot.getKey());

                Log.v("VALUES",""+ childDataSnapshot.child(childDataSnapshot.getKey()).getValue());
            }
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });


但它是空的,我无法阅读其中的任何内容。

java - 我想列出微调Firebase中所有唯一的子代和键以及值。-LMLPHP

最佳答案

您已经写了Medical而不是“ Medicines”。

您可以删除或保留此选项,因为其余的看上去正确

此外,childSnapshot.getKey()会给您日期,而childSnapshot.getValue()会给您整个日期

另外,如果我得到了您,那么您可以尝试以下操作:

  mUserDatabase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            for (DataSnapshot childDataSnapshot : dataSnapshot.getChildren()) {

             //"DATES:"+dataSnapshot.getKey()

                for (DataSnapshot childDataSnapshot2 : childDataSnapshot.getChildren()) {

             // "MEDICINE NAME"+childDataSnapshot2.getKey()

                    arrayList.add(childDataSnapshot2.getKey());

             //"VALUES"+childDataSnapshot2.getValue()

                }
                }

        }
        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

07-24 09:30