我创建了CardViews,它会显示作为背景输入的URL中的图像,但不知何故卡片上没有任何显示。
我实际上正在使用RecyclerView和FireBase数据库来显示卡片。
RecyclerViewAdapter
class RecyclerViewAdapter extends
RecyclerView.Adapter<RecyclerViewAdapter.MyHoder> {
private List<Groups> list;
private Context context;
public RecyclerViewAdapter(List<Groups> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public MyHoder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.recycler_view_groups,parent,false);
MyHoder myHoder = new MyHoder(view);
return myHoder;
}
@Override
public void onBindViewHolder(MyHoder holder, int position) {
Groups mylist = list.get(position);
holder.name.setText(mylist.getGroupName());
holder.banner.setImageDrawable(LoadImageFromWebOperations(mylist.getGroupBannerImage()));
//^^Image assignment to the ImageView not working
//mylist.getGroupBannerImage() returns the URL string of the image I want as the card's background
}
public static Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
@Override
public int getItemCount() {
int arr = 0;
try{
if(list.size()==0){
arr = 0;
}
else{
arr=list.size();
}
}catch (Exception e){
}
return arr;
}
class MyHoder extends RecyclerView.ViewHolder{
TextView name,address;
ImageView banner;
public MyHoder(View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.groupName);
banner= (ImageView) itemView.findViewById(R.id.groupBannerImage);
//address= (TextView) itemView.findViewById(R.id.vaddress);
}
}
}
我缺少什么吗?我的其他显示数据在CardView中正确显示,但只有图像没有出现。