我从我的intent extras (KI1,KI2等)接收字符串数组名称
不是硬编码字符串数组名称(如r.a ray. ki1),我想用变量替换它们。
strdata = receiverIntent.getExtras().getString("intentExtra");
String[] pointDetails = getResources().getStringArray**(R.array.KI1);**
资源文件
<resources>
<string-array name="KI1">
<item>Categories Text KI1</item>
<item>Unitary Channel Text KI1</item>
<item>Localization Text KI1</item>
<item>Action Text KI1</item>
<item>Indication Text KI1</item>
<item>Point location Text KI1</item>
<item>KI1.png</item>
</string-array>
<string-array name="KI2">
<item>Categories Text KI2</item>
<item>Unitary Channel Text KI2</item>
<item>Localization Text KI2</item>
<item>Action Text KI2</item>
<item>Indication Text KI2</item>
<item>Point location Text KI2</item>
<item>KI2.png</item>
</string-array>
</resources>
为什么不可能这样做呢?
String[] pointDetails = getResources().getStringArray("R.array." + strdata);
我希望变量的输出像这样:r.a ray.strdata
因为getStringArray();接受整型值,但传递字符串给它。
为什么不用switch case或者if exp…像
String[] pointDetails ;
switch(strdata)
{
case "KI1":
pointDetails = getResources().getStringArray(R.array.KI1);
break;
case "KI2":
pointDetails = getResources().getStringArray(R.array.KI2);
break;
}