1
我已经看到了关于这个问题的几个线程,但我不知道他们为什么不为我工作。这里的短代码:通过名称获取字符串资源
//This doesn't work. I'm getting a 0 id
id=getResources().getIdentifier("q1", "id", getPackageName());
//This retrieves the string correctly (just to prove the string is called q1
String str=getResources().getString(R.string.q1);
我能想到的唯一的问题是packagename的问题,但它似乎确定。
任何帮助?