我无法从firebase数据库中检索数据列表。相反,它仅作为字符串值列出。我如何检索数据

时间:2018-02-18 11:22:22

标签: android firebase arraylist

FullDbStructure我无法从firebase数据库中检索数据列表。相反,它仅作为字符串值列出。我该如何检索数据?这就是我尝试检索数据的方式。      这是我的主要活动

        database.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for(DataSnapshot child: dataSnapshot.getChildren()){
                    for(DataSnapshot child1: child.getChildren()){
                        if(child1.getKey().equalsIgnoreCase("Imagelist")){
                            Log.e("retrievedsuccess","retrievedsuccess"+child1.getKey());
                            imagelist.add(child1.getValue().toString());


                        }
                        else if(child1.getKey().equalsIgnoreCase("Namelist")){
                            Namelist.add(child1.getValue().toString());
                            Log.e("namelistretrieved","namelistretrieved"+Namelist);
                        }
                        else if(child1.getKey().equalsIgnoreCase("desclist")){
                            desclist.add(child1.getValue().toString());
                        }
                        else if(child1.getKey().equalsIgnoreCase("pricelist")){
                            pricelist.add(child1.getValue().toString());

                        }
                        else if(child1.getKey().equalsIgnoreCase("offerpricelist")){
                            offerpricelist.add(child1.getValue().toString());
                        }
                       ad = new Adapteradmin(imagelist,Namelist,desclist,pricelist,offerpricelist,getApplicationContext());
                        REC.setAdapter(ad);
                    }
                }
            }

//这是我的适配器类,我在其中添加了代码来设置图像并添加名称,desc,价格和报价,请告诉我如何在" order"下从中检索数据火力

public class Adapteradmin extends RecyclerView.Adapter<Viewholderadmin> {
ArrayList<String> Imagelist;
    ArrayList<String> Namelist;
    ArrayList<String> Desclist;
    ArrayList<String> Pricelist;
    ArrayList<String> Offerpricelist;

private Context context;
//ViewdetailsAdmin viewdetailsAdmin;


    public Adapteradmin(ArrayList<String> imagelist, ArrayList<String> namelist, ArrayList<String> desclist, ArrayList<String> pricelist, ArrayList<String> offerpricelist, Context context) {
        this.Imagelist = imagelist;
       this.Namelist = namelist;
        this.Desclist = desclist;
        this.Pricelist = pricelist;
       this.Offerpricelist = offerpricelist;
        this.context = context;
    }

    @Override
    public Viewholderadmin onCreateViewHolder(ViewGroup parent, int viewType) {
        View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.layoutadmin,parent,false);
        return new Viewholderadmin(v);
    }


    @Override
    public void onBindViewHolder(Viewholderadmin holder, int position) {
        Picasso.with(context).load(this.Imagelist.get(position)).into(holder.I);
holder.Name.setText(Namelist.get(position));

holder.Desc.setText(Desclist.get(position));
holder.Price.setText(Pricelist.get(position));
holder.Offer.setText(Offerpricelist.get(position));
    }

    @Override
    public int getItemCount() {
        return Imagelist.size();
    }
}

"


[DATABASE STRUCTURE][1]


  [1]: https://i.stack.imgur.com/fPXrB.png

1 个答案:

答案 0 :(得分:0)

例如,要显示urls,请使用以下代码:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference ref = rootRef.child("crazycollections").child("Orders").child(date).child(Imagelist);
ValueEventListener eventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            String url = ds.getValue(String.class);
            Log.d("TAG", url);
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {}
};
ref.addListenerForSingleValueEvent(eventListener);

dateSun Feb 18...