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的問題,但它似乎確定。
任何幫助?