How can i add image to ListView
?
如何將圖像添加到ListView?
I put images in assets folder and the name of the image in database table.
我將圖像放在資源文件夾中,並將圖像的名稱放在數據庫表中。
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);
}
}
something like this:
像這樣的東西:
0
Integer[] imageId = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
R.drawable.image6,
R.drawable.image7
};
Pass the ids through adapter:
通過適配器傳遞ID:
CustomList adapter = new
CustomList(MainActivity.this, data, imageId);
Pass the resource ids of your images through the Adapter class's constructor and set to the ImageView
like
通過Adapter類的構造函數傳遞圖像的資源ID,並設置為ImageView
iv.setImageResource(imageId[position]);
Refer this tutorial
請參閱本教程
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/12/07/4defecec12d2cf8c0fdcb99f192a876.html。