サーバーからイベントに関するデータを受け取る Android アプリケーションを開発しています。
ListView に、イベントの名前とカテゴリ、および写真を入れます。私の問題は次のとおりです。各カテゴリには特定の画像が必要です。drawable フォルダー内のどの画像を表示するかを選択するにはどうすればよいですか?
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);