0
我正在開發一個android應用程序,它接收有關來自服務器的事件的數據。選擇可繪製文件路徑
在ListView中,我把事件和圖片的名稱和類別。 我的問題是:每個類別應該有一個特定的圖片。如何選擇可繪製文件夾中的哪些圖片應顯示?
View v; /**I get this view from the parameters.**/
ImageView iconCategory = (ImageView) v .findViewById(R.id.category_icon);
Drawable drawable = null;
if (o.getCategoria().equals("category1")) {
/* here I want to set the icon to the file named icon_category1.png . I wanna do that by instantiating drawable */
} else if (o.getCategoria().equals("category2")) {
/* here I want to set the icon to the file named icon_category2.png I wanna do that by instantiating drawable */
} else if (o.getCategoria().equals("category3")) {
/* here I want to set the icon to the file named icon_category3.png I wanna do that by instantiating drawable */
}
iconCategory.setImageDrawable(drawable);