获取所有数据并从firebase插入arraylist

时间:2018-06-06 05:52:40

标签: android firebase arraylist

我想从firebase获取所有颜色数据然后插入到arraylist,颜色数据结构如下图所示 enter image description here

这是我想插入Arraylist

的时候
private void getDataDetailProduct() {
    imageReference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()){
                for (DataSnapshot childSbapshot : dataSnapshot.getChildren()){
                    String id = childSbapshot.getKey();

                    ArrayList<String>images = new ArrayList<>();                        
                    images.add(String.valueOf(childSbapshot.getChildren()));
                }
                initSlideImage();
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}

1 个答案:

答案 0 :(得分:1)

ArrayList<String>images = new ArrayList<>(); 

private void getDataDetailProduct() {
    imageReference.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()){
                for (DataSnapshot childSbapshot : dataSnapshot.getChildren()){
                    String id = childSbapshot.getKey();
                    images.add(String.valueOf(childSbapshot.child("colors1").getValue()));
                    images.add(String.valueOf(childSbapshot.child("colors2").getValue()));
                    images.add(String.valueOf(childSbapshot.child("colors3").getValue()));
                }
        initSlideImage();
        }}

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}