如何从Firebase检索数据到适配器
public String image_thumb;public String user_id;public String image_url;public String desc;public BlogPost(){} public BlogPost(String user_id, String image_url, String desc, String image_thumb) { this.user_id = user_id; this.image_url = image_url; this.desc = desc; this.image_thumb = image_thumb;}public String getUser_id() { return user_id;}public void setUser_id(String user_id) { this.user_id = user_id;}public String getImage_url() { return image_url;}public void setImage_url(String image_url) { this.image_url = image_url;}public String getDesc() { return desc;}public void setDesc(String desc) { this.desc = desc;}public String getImage_thumb() { return image_thumb;}public void setImage_thumb(String image_thumb) { this.image_thumb = image_thumb;}
public void onBindViewHolder(final ViewHolder holder, int position) { String desc_data = blog_list.get(position).getDesc(); holder.setDescText(desc_data);//this works String image_url = blog_list.get(position).getImage_url(); holder.setBlogImage(image_url);//this works String user_id = blog_list.get(position).getUser_id(); firebaseDatabase.child("Users").child(user_id).addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if(dataSnapshot.exists()){ String userName = dataSnapshot.child("name").getValue().toString(); holder.setUserName(userName); } } @Override public void onCancelled(DatabaseError databaseError) { } }); public void setUserName(String name){ blogUserName = mView.findViewById(R.id.blog_user_name); blogUserName.setText(name); }
TextView