Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1): In <code>prefsEditr.putFloat("strength", -1);</code> the value "-1" is an Integer and therefore stored as an Integer. You could use <code>Float.parseFloat</code> to parse an Integer (eg parsing the stored Integer value or parsing an Integer value and store it).</p> <p>Can you please elaborate 2) and 3)? I did not get what <em>exactly</em> you meant.</p> <p>/edit: Some sample code for saving / reading an array</p> <pre><code>public String[] readArray() { SharedPreferences openPreferences = context.getSharedPreferences("arrayfile", Context.MODE_PRIVATE); final Integer counter = openPreferences.getInt("size", 0); String[] result = new String[counter]; for (int i=0;i&lt;counter;i++) { result[i] = openPreferences.getString("entry_"+i, ""); } return result; } public void writeArray(String[] array) { Editor editor = context.getSharedPreferences("arrayfile", Context.MODE_PRIVATE).edit(); final Integer counter =array.length; editor.putInt("size", counter); for (int i=0;i&lt;counter;i++) { editor.putString("entry_"+i, array[i]); } editor.commit(); } </code></pre> <p>/edit: Also use a <code>PreferenceActivity</code> instead of a <code>ListActivity</code>. That makes things easier.</p> <p>Then add this code in <code>OnCreate()</code>:</p> <pre><code> PreferenceManager localPreferenceManager = getPreferenceManager(); localPreferenceManager.setSharedPreferencesName("main_prefs"); localPreferenceManager.setSharedPreferencesMode(MODE_PRIVATE); [for every entry do:] { addNewPref("ArrayValue"); } </code></pre> <p>and then add dynamically Preference Views to the Activity, just adjust the code below:</p> <pre><code> private void addNewPref(String title) { Preference newPref = new Preference(this); newPref.setTitle(title); ((PreferenceScreen) getPreferenceManager().findPreference("category_key")).addItemFromInflater(newPref); } </code></pre> <p>Content of the <code>PreferenceScreen</code> XML:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;PreferenceScreen android:key="category_key" xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;/PreferenceScreen&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload