我正在解析vk的羣組牆。有些帖子有照片(從1到10),有些沒有。我需要展示它們。但是,所有的圖像都會重複。我無法讓它們正確顯示。目前我正在使用畢加索。它說它可以處理ListView圖像,但它不會。我在谷歌上的其他方式也不起作用。問題是如何正確處理圖像。這是一段負責照片的代碼。重複ListView中的圖像
private void place_photos(View view, ArrayList<VKPhoto> photos) {
int pcount = photos.size();
final View v = view;
TableRow first = (TableRow)v.findViewById(R.id.first_row);
TableRow second = (TableRow)v.findViewById(R.id.second_row);
TableRow third = (TableRow)v.findViewById(R.id.third_row);
for (int i = 0; i < pcount; i++) {
if (i == 1) {
ImageView img = new ImageView(mContext);
String url = photos.get(i).photo_807;
img.setTag(url);
Picasso.with(mContext).load(url).into(img);
if (first != null)
first.addView(img);
}
if (i == 2 || i == 3) {
ImageView img = new ImageView(mContext);
String url = photos.get(i).photo_807;
img.setTag(url);
Picasso.with(mContext).load(url).into(img);
if (second != null)
second.addView(img);
}
if (i > 3) {
ImageView img = new ImageView(mContext);
String url = photos.get(i).photo_807;
img.setTag(url);
Picasso.with(mContext).load(url).into(img);
if (third != null)
third.addView(img);
}
}
}
這就是它是如何調用getView方法:
if (post.attachments.hasPhoto) {
place_photos(v, post.attachments.photos);
} else {
viewHolder.photo_wrapper.setVisibility(View.GONE);
}
UPD 以下是完整的適配器代碼:https://gist.github.com/alexbat98/7f22598e7e73d301a4ef
如果你使用自定義的適配器粘貼這裏的代碼 –
@ Kat-hat上傳到Gist –
我不知道,但你設置viewholder.photo? – Cocorico