我有一个XML文件:
<building>
<room IMAGE="R.raw.room" />
</building>
但我不知道如何将IMAGE的值链接到我的主程序......当我这样做时:
[... parsing xml file and detect room ...]
ImageView image = findViewByID(xml.getAttributeValue(0));
它不起作用..因为它返回一个字符串而不是一个int。如何将此XML文件链接到我的资源?
请帮忙!
答案 0 :(得分:2)
您是否尝试过使用getResources()。getIdentifier()?
已回答here
答案 1 :(得分:0)
R.raw.room
是编译器为文件生成的标识符。您无法从XML加载。你想要达到什么目标?