将XML链接到资源

时间:2011-06-10 11:52:45

标签: android xml uiimageview

我有一个XML文件:

<building>
    <room IMAGE="R.raw.room" />
</building>

但我不知道如何将IMAGE的值链接到我的主程序......当我这样做时:

[... parsing xml file and detect room ...]
ImageView image = findViewByID(xml.getAttributeValue(0));

它不起作用..因为它返回一个字符串而不是一个int。如何将此XML文件链接到我的资源?

请帮忙!

2 个答案:

答案 0 :(得分:2)

您是否尝试过使用getResources()。getIdentifier()?

已回答here

答案 1 :(得分:0)

R.raw.room是编译器为文件生成的标识符。您无法从XML加载。你想要达到什么目标?