(我在 res/drawable 中有图像,数据库中的图像名称)我已经完成将图像从 res/drawable 显示到列表视图,但图像显示相同的图片..我想显示与其他图像不同的图像....
如何从可绘制文件夹更改图像 ID(使用 setImageResource())。我的可绘制文件夹包含超过 1 个图像,我想使用已存储的数据库中的名称更改这些图像..
这是我的教程中的代码...
//数据库的结果(image2.jpg)
public KontakItemListBaseAdapter(Context context, ArrayList<KontakItemDetails> results) {
itemDetailsrrayList = results;
l_Inflater = LayoutInflater.from(context);
}
public int getCount() {
return itemDetailsrrayList.size();
}
public Object getItem(int position) {
return itemDetailsrrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
try{
ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.kontak_details_view, null);
holder = new ViewHolder();
holder.txt_itemName = (TextView) convertView.findViewById(R.id.name);
holder.txt_itemDescription = (TextView) convertView.findViewById(R.id.itemDescription);
holder.itemImage = (ImageView) convertView.findViewById(R.id.photo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txt_itemName.setText(itemDetailsrrayList.get(position).getName());
holder.txt_itemDescription.setText(itemDetailsrrayList.get(position).getItemDescription());
holder.itemImage.setImageResource(R.drawable.iddy);
}catch (Exception ex) {
throw new Error("kontakitemlistadapter :"+ex.toString());
}
return convertView;
}
static class ViewHolder {
TextView txt_itemName;
TextView txt_itemDescription;
TextView txt_itemPrice;
ImageView itemImage;
}
我想我的问题在这里..
holder.itemImage.setImageResource(R.drawable.iddy);
如何将 R.drawable.iddy 更改为路径名?