我有一个使用recyclerView的活动。此回收者视图包含图像。但滑行并没有显示任何东西。只是黑色方块。我试图通过URL和SD卡从互联网上加载图像。
public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.MyViewHolder> {
private ArrayList<Integer> list;
private Context context;
public MyRecyclerViewAdapter(ArrayList<Integer> list, MainActivity context) {
this.list = list;
this.context = context.getApplicationContext();
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
ImageView photo;
public MyViewHolder(View itemView) {
super(itemView);
photo = (ImageView) itemView.findViewById(R.id.photo);
}
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_for_recycler_view, viewGroup, false);
MyViewHolder myViewHolder = new MyViewHolder(v);
return myViewHolder;
}
@Override
public void onBindViewHolder(MyViewHolder viewHolder, int i) {
// viewHolder.photo.setImageResource(list.get(i));
ImageView imageView = viewHolder.photo;
Glide.with(context).load(list.get(i)).into(imageView);
}
@Override
public int getItemCount() {
return list.size();
}
}