在過去的一個小時裏,我一直試圖弄清楚這一點。
我想一般從strings.xml
得到字符串,並在我的代碼,所以我可以動態更改字符串的數量,而無需更改我的代碼中的任何東西,將它們加載到數組列表中。
到目前爲止,我只有如何從strings.xml中獲取字符串值並進入arraylist [android]
for(Field x :R.string.class.getFields())
if(x.getName().startsWith("ans"))
choices.add(/*what do I add here to get the string value from the field in to the arraylist */);
我想不出我的生活如何得到字符串值了現場的對象。我得到的所有內容都是Id(或者至少我認爲是Id)或我在strings.xml
文件中分配的名稱。
是的,只是不得不改變x.get(null)並將其作爲一個整數和環繞一個嘗試,趕上 但這是我渴望的正確解決方案。 –
有人請這個。 –
try {choices.add(res.getString((Integer)x.get(null))); } //這獲取ID,然後抓住相關 \t \t \t \t \t \t \t \t趕上(拋出:IllegalArgumentException E){e.printStackTrace()的資源;} \t \t \t \t趕上(IllegalAccessException E){e.printStackTrace ();} \t} –