ArrayAdapterを継承したクラスで、ListViewを表示しています。
その行のテキスト要素に画像URLがあれば、
その画像の数だけ、行にImageViewを追加し、サムネイル表示の様にしたいのですが、
以下のコードの様にすると、画像要素の無い行にもどこかのサムネイルが出たり、繰り返し表示をしたりしてしまいます。
viewを再利用しているからかな?と思いましたが、解決方法が分かりません。
任意の行だけにサムネイルを表示させるにはどうしたら良いでしょうか?
宜しくお願いします!
public class TestAdapter extends ArrayAdapter<Item> {
~~~
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = layoutInflater_.inflate(R.layout.list_row, null);
}
final Item item = this.getItem(position);
LinearLayout ll = (LinearLayout) convertView
.findViewById(R.id.list_rowLL);//親のview
tvBody = (TextView) convertView.findViewById(R.id.tvBody);
tvBody.setText(item.getFldBody());//テキスト表示の為のview
//画像があれば、画像数分ImageViewを追加
if (item.getImgAry() != null) {
for (int i = 0; i < item.getImgAry().size(); i++) {
ImageView img = new ImageView(_con);
img.setBackgroundDrawable(item.getImgAry().get(i));
img.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
ll.addView(img);
}
}
return convertView;
}
}
//Itemクラス
public class Item {
private String fldBody;
private ArrayList<Drawable> imgAry;//fldBody内に画像URLがあれば、画像を取得してきてこの配列に入れている。
public Item() {
setFldBody("");
setImgAry(null);
}
public String getFldBody() {
return fldBody;
}
public void setFldBody(String fldBody) {
this.fldBody = fldBody;
}
public ArrayList<Drawable> getImgAry() {
return imgAry;
}
public void setImgAry(ArrayList<Drawable> imgAry) {
this.imgAry = imgAry;
}
}
> android-group-japan+unsub...@googlegroups.com にメールを送信してください。