リスト行レイアウト内に SmartImageView ( http://loopj.com/android-smart-image-view/ )を持つカスタム リストビューがあります。
各行の各 SmartImageView を画像に設定しようとしています。以下は私のリストアダプターです。
private class MyListAdapter extends ArrayAdapter<ListItem> {
private ArrayList<ListItem> items;
public MyListAdapter(Context context, int textViewResourceId, ArrayList<ListItem> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.item_row_layout, null);
}
ListItem o = items.get(position);
if (o != null) {
TextView title = (TextView) v.findViewById(R.id.ptitle);
TextView site = (TextView) v.findViewById(R.id.site);
TextView price = (TextView) v.findViewById(R.id.price);
SmartImageView img = (SmartImageView) findViewById(R.id.smallimage);
Typeface font = Typeface.createFromAsset(getAssets(), "Asap-Regular.ttf");
site.setTypeface(font);
title.setTypeface(font);
price.setTypeface(font);
if (title != null) {
title.setText(o.getTitle());
}
if (site != null) {
site.setText("Supplier Name");
}
if (price != null) {
price.setText("£"+ String.valueOf(o.getPrice()));
}
if (img != null){
String url = o.getImage();
img.setImageUrl(url);
}
}
return v;
}
}
他のすべてのもの、つまりタイトル、価格などは問題なく設定されますが、画像は正しく設定されません。
複数のリスト項目がある場合、一番上の項目が最後の項目の画像を取得し、残りの項目には画像が設定されていません。リストにアイテムが1つある場合、画像セットはまったく取得されません。
コードや情報がさらに必要な場合は、お知らせください。