如何检查资源android studio

时间:2017-05-04 09:08:04

标签: android xml android-resources file-exists

我在xml文件夹下的res文件夹中有一个xml文件。我需要检查这个文件是否存在。我使用getidentifier检查存在但是我收到了错误。

image

如图所示。如果checkExistence = 1(如果文件存在),我有一个名为checkExistence的整数。但是应用程序不起作用。可能导致这种情况的原因是什么?

1 个答案:

答案 0 :(得分:0)

最后我解决了这个问题..我所做的是:

Context context=this;
int checkExistence;

...

...

...

final String resourcename= String.valueOf(R.xml.xmlfiletocheck);
    checkExistence = context.getResources().getIdentifier(resourcename,"xml",context.getPackageName());

...

...

if(checkExistence!=0) {
//if number is different than 0, it means file exists
..
..
}
相关问题