title: Read sharedpreferences default values from XML array
body: <p>I'm trying to make my app read sharedpreferences default values from XML array but I have a problem achieving that. Let's say for example that I have 20 checkboxes, I inserted 20 items to string-array in strings.xml. Now what I'm trying to do is simple, I want my sharedpreferences to read default values from this array. Checkbox1 will get the first item name, checkbox2 will get the second item name and so on. The code below shows what I tried to do.</p>
  
  <p>XML array:</p>
  
  <pre><code>&lt;string-array name="spBifrost"&gt;
      &lt;item&gt;Elaborate Totem (250)&lt;/item&gt;
      &lt;item&gt;Pile of Crystalline Dust (250)&lt;/item&gt;
      &lt;item&gt;Powerful Venom Sac (250)&lt;/item&gt;
      &lt;item&gt;Vial of Powerful Blood (250)&lt;/item&gt;
      &lt;item&gt;Ancient Bone (250)&lt;/item&gt;
      &lt;item&gt;Armored Scale (250)&lt;/item&gt;
      &lt;item&gt;Vicious Claw (250)&lt;/item&gt;
      &lt;item&gt;Vicious Fang (250)&lt;/item&gt;
      &lt;item&gt;Glob of Ectoplasm (77)&lt;/item&gt;
      &lt;item&gt;Glob of Ectoplasm (77)&lt;/item&gt;
      &lt;item&gt;Mystic Coin (77)&lt;/item&gt;
      &lt;item&gt;Obsidian Shard (77)&lt;/item&gt;
      &lt;item&gt;Philosophers Stone (462)&lt;/item&gt;
      &lt;item&gt;Badge of Honor (500)&lt;/item&gt;
      &lt;item&gt;Obsidian Shard (250)&lt;/item&gt;
      &lt;item&gt;Shard of Zhaitan (500)&lt;/item&gt;
      &lt;item&gt;Opal Orb (100)&lt;/item&gt;
      &lt;item&gt;Pile of Crystalline Dust (250)&lt;/item&gt;
      &lt;item&gt;Unidentified Dye (250)&lt;/item&gt;
      &lt;item&gt;Pile of Crystalline Dust (250)&lt;/item&gt;
      &lt;item&gt;Pile of Incandescent Dust (250)&lt;/item&gt;
      &lt;item&gt;Pile of Luminous Dust (250)&lt;/item&gt;
      &lt;item&gt;Pile of Radiant Dust (250)&lt;/item&gt;
      &lt;item&gt;Icy Runestone (100)&lt;/item&gt;
  &lt;/string-array&gt;
  </code></pre>
  
  <p>Sharedpreferences get code in java:</p>
  
  <pre><code>private String getItemQuantity(String key){
      SharedPreferences itemQuantitySP = getApplicationContext().getSharedPreferences("bifrostPrefs", android.content.Context.MODE_PRIVATE);
      Resources spRes = getResources();
      TypedArray itemNames = spRes.obtainTypedArray(R.array.spBifrost);
      String itemSp = itemNames.toString();
      return itemQuantitySP.getString(key, itemSp);
  }
  </code></pre>
  
  <p>Now when I actually use this code, it doesn't work how I want it to at all. For example, instead of renaming checkbox1 to "Elaborate Totem (250)" it renames it to a bunch of random numbers that I do not understand. Could someone tell me what I am doing wrong? I am a complete beginner (started learning java/android developing a month ago) so there's a big chance I approached this completely wrong and that's why I'm asking for your help. </p>
  
  <p>Java code now:</p>
  
  <pre><code>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);
      ArrayList&lt;String&gt; spBifrostArray = new ArrayList&lt;String&gt;();
      return itemQuantitySP.getString(key, spBifrostArray.toString());
  }
  </code></pre>