我正在尝试从我在 XML 文件中创建的字符串数组中读取 sharedpreferences 默认值。
Sharedpreferences 获取 java 代码:
private String getItemQuantity(String key){
SharedPreferences itemQuantitySP = getApplicationContext().getSharedPreferences("bifrostPrefs", android.content.Context.MODE_PRIVATE);
Resources res = getResources();
String[] spBifrost = res.getStringArray(R.array.spBifrost);
return itemQuantitySP.getString(key, spBifrost.toString());
}
字符串数组 XML:
<string-array name="spBifrost">
<item>Elaborate Totem (250)</item>
<item>Pile of Crystalline Dust (250)</item>
<item>Powerful Venom Sac (250)</item>
<item>Vial of Powerful Blood (250)</item>
<item>Ancient Bone (250)</item>
<item>Armored Scale (250)</item>
<item>Vicious Claw (250)</item>
<item>Vicious Fang (250)</item>
<item>Glob of Ectoplasm (77)</item>
<item>Glob of Ectoplasm (77)</item>
<item>Mystic Coin (77)</item>
<item>Obsidian Shard (77)</item>
<item>Philosophers Stone (462)</item>
<item>Badge of Honor (500)</item>
<item>Obsidian Shard (250)</item>
<item>Shard of Zhaitan (500)</item>
<item>Opal Orb (100)</item>
<item>Pile of Crystalline Dust (250)</item>
<item>Unidentified Dye (250)</item>
<item>Pile of Crystalline Dust (250)</item>
<item>Pile of Incandescent Dust (250)</item>
<item>Pile of Luminous Dust (250)</item>
<item>Pile of Radiant Dust (250)</item>
<item>Icy Runestone (100)</item>
</string-array>
现在,每当我使用 sharedpreferences 时,它都会自动将默认值读取为 [Ljava.lang.String;@435ec530 并且我不知道它从哪里得到它以及如何修复它。我有 24 个复选框,我希望它使用复选框 1 的第一项,复选框 2 的第二项等。
调用 getItemQuantity:
cb4.setText(getItemQuantity("cb4quantity"));
String[] spBifrost = getItemQuantity("cb4quantity").split(";");