我想列出微调Firebase中的所有唯一子项和键以及值 [英] I want to list all unique childrens and keys along with values in a spinner firebase

查看:67
本文介绍了我想列出微调Firebase中的所有唯一子项和键以及值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的实时数据库. Users => UID => Medicines => Date => Medicine Name:值

I have my realtime database as this. Users=>UID=>Medicines=>Date=>Medicine Name :Values

我有一个微调器

 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) {

        }
    });

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

BUT IT IS EMPTY AND I AM UNABLE TO READ ANY OF THEM.

推荐答案

您写的是Medical而不是"Medicines".

You have written Medical instead of "Medicines".

您可以删除它,也可以保留其余状态,直到其余一切正确为止

You can either delete or leave this as solved as rest looks correct

childSnapshot.getKey()还可以为您提供日期,而childSnapshot.getValue()还可以为您提供日期范围内的全部信息

Also childSnapshot.getKey() will give you DATES and childSnapshot.getValue() will give you entire thing inside date

如果我找到了你,那么你可以尝试一下:

Also If I got you then you can try this:

  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) {

        }
    });

这篇关于我想列出微调Firebase中的所有唯一子项和键以及值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆