如何将图片添加到ListView
?
我将图片放在assets文件夹中,并将图片名称放在数据库表中。
class Aray extends ArrayAdapter<String> {
public Aray() {
super(ChapterList.this, R.layout.chapterlist, chapName);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater in = getLayoutInflater();
View row = in.inflate(R.layout.chpter_row, parent, false);
TextView cName = (TextView) row.findViewById(R.id.chap_name_row);
TextView sCount = (TextView) row.findViewById(R.id.chap_count_row);
ImageView iv = (ImageView) row.findViewById(R.id.ivrow);
iv.???
cName.setText(chapName[position]);
sCount.setText(storyCount[position]);
return (row);
}
}
类似的东西:
答案 0 :(得分:0)
Integer[] imageId = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
R.drawable.image6,
R.drawable.image7
};
通过适配器传递ID:
CustomList adapter = new
CustomList(MainActivity.this, data, imageId);
通过Adapter类的构造函数传递图像的资源ID并设置为ImageView
iv.setImageResource(imageId[position]);