私は 8 ボール アプリケーションを作成しており、リフレクションを使用して、strings.xml ファイルから文字列を取得して ArrayList に入れていますが、そのすべてのことは、そこにある既定の文字列を見つけることです (hello_world でさえ、私が削除されました) また、文字列値が入っている Field クラスから文字列値を取得する方法がわかりません。
最初の System.out.println() [フィールドの量] は 4 になります。これらはすべて、デフォルトの strings.xml ファイルのデフォルト値であり、追加/削除されたリソースは更新も表示もされていません。
また、その奇妙なトレースファイルエラーが発生しています
デバッガーでは、ansStuff のサイズが 23 になっています... [[4 ではないと思われる量]] とても奇妙です
Field[] ansStuff = R.string.class.getFields();
System.out.println(R.string.class.getFields().length);
for(Field x :ansStuff){
System.out.println(x);
System.out.println(x.getName());
System.out.println(x.toString());
if(x.getName().startsWith("ans")){
choices.add(/*the goddamned string*/"poop");
}
}
デバッグの混乱を取り除いた後、これに変換されます
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 */);
ここにリソースファイルがあります
<resources>
<string name="app_name">8ballRotate</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="ans0">It is certain</string>
<string name="ans1">It is decidedly so</string>
<string name="ans2">Without a doubt</string>
<string name="ans3">Yes – definitely</string>
<string name="ans4">You may rely on it</string>
<string name="ans5">As I see it, yes</string>
<string name="ans6">Most likely</string>
<string name="ans7">Outlook good</string>
<string name="ans8">Yes</string>
<string name="ans9">Signs point to yes</string>
<string name="ans10">Reply hazy, try again</string>
<string name="ans11">Ask again later</string>
<string name="ans12">Better not tell you now</string>
<string name="ans13">Cannot predict now</string>
<string name="ans14">Concentrate and ask again</string>
<string name="ans15">Don\'t count on it</string>
<string name="ans16">My reply is no</string>
<string name="ans17">My sources say no</string>
<string name="ans18">Outlook not so good</string>
<string name="ans19">Very doubtful</string>
</resources>