Android 选择可绘制文件路径

Android 选择可绘制文件路径,android,drawable,Android,Drawable,我正在开发一个android应用程序,它从服务器接收有关事件的数据 在列表视图中,我放置了事件的名称和类别以及一张图片。 我的问题是:每个类别都应该有一个特定的图片。如何选择应显示可绘制文件夹中的哪些图片 View v; /**I get this view from the parameters.**/ ImageView iconCategory = (ImageView) v .findViewById(R.id.category_icon); Drawable drawable = nu

我正在开发一个android应用程序,它从服务器接收有关事件的数据

在列表视图中,我放置了事件的名称和类别以及一张图片。 我的问题是:每个类别都应该有一个特定的图片。如何选择应显示可绘制文件夹中的哪些图片

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);
你能行

Drawable d = getResources().getDrawable(R.drawable.icon_category2);
iconCategory.setImageDrawable(d);
文件名的第一部分是可绘制id