我试图从数组列表中调出特定字符串,而不是运行具有许多单独字符串值的非常大的 switch case。我在xml中有数组列表
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="type_items">
<item name="kitchen_0">spoon</item>
<item name="kitchen_1">fork</item>
<item name="bathroom_0">toothbrush</item>
<item name="bathroom_1">hair brush</item>
</string-array>
</resources>
在代码中,用户将做出 2 个选择。一个用于房间,另一个用于物品。然后程序将生成项目结果作为字符串输出。
public String result(int room, int item)
{
String roomID = getResources().getStringArray(R.array.roomlist)[room] + "_" +
String.valueOf(item);
return //needs to return "toothbrush" if roomID is bathroom_0
}
现在我试图从数组列表中返回与该组合关联的值,在四处搜索之后我找不到答案。也许答案是我做错了。任何帮助表示赞赏。
慕丝7291255
相关分类