我有一個圖像url的數組,我想用Picasso下載圖像並在網格視圖中顯示它們。我當前的實現工作,但它將最後一張圖像放入網格視圖的每個圖像視圖中。從數組填充GridView
public class GridViewAdapter extends ArrayAdapter {
Context context;
public GridViewAdapter(Context context) {
super(context, 0);
this.context = context;
}
public int getCount() {
return thumbnailURLS.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if(row == null) {
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(R.layout.grid_row, parent, false);
ImageView gridImageView = (ImageView)row.findViewById(R.id.gridImageView);
for(String s : thumbnailURLS) {
Picasso.with(context)
.load(s)
.placeholder(R.drawable.placeholder)
.error(R.drawable.placeholder)
.into(gridImageView);
}
}
return row;
}
}