无法从firebase的随机列表数据中检索数据

时间:2017-04-26 03:40:38

标签: android firebase-realtime-database

我想从firebase数据库中检索数据,结构将遵循此图像 enter image description here

我正在使用以下代码

 private DatabaseReference mDatabase;

    private ListView poemListView;

    private ArrayList<String> poemList =new ArrayList<>();

    ArrayAdapter<String> arrayAdapter;

    public void onCreate(Bundle savedInstanceState) {

        final Spinner dropdown = (Spinner)findViewById(R.id.spinner1);

        String[] items = new String[]{"Father","Mom","Love", "FreindShip", "Nature","Happy","Inspiration","Sad"};

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items);

        dropdown.setAdapter(adapter);

        String dropDownString=dropdown.getSelectedItem().toString();

  mDatabase=FirebaseDatabase.getInstance().getReference().child(dropDownString);


 poemListView = (ListView)findViewById(R.id.poemList);

 arrayAdapter=new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_1,poemList);

        poemListView.setAdapter(arrayAdapter);

        mDatabase.addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                String value=dataSnapshot.getValue(String.class);

                poemList1.add(value);

                arrayAdapter.notifyDataSetChanged();
            }

当我调试代码时,代码运行良好,直到

{ String value=dataSnapshot.getValue(String.class); }

for ex:在父catogery下只获取一个记录(在调试模式下检查)。

帮助我检索列表中的所有数据

0 个答案:

没有答案