Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This might help you get back on track and having working preferences:</p> <p>XML FILE: preferences.xml </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;PreferenceCategory android:title="Preferences Font"&gt; &lt;EditTextPreference android:title="Select Font Size" android:key="foobar" android:summary="Enter Font Size" android:defaultValue="12" /&gt; &lt;/PreferenceCategory&gt; &lt;/PreferenceScreen&gt; </code></pre> <p>JAVA FILE 1: Home.java</p> <pre><code>public class Home extends Activity { public SharedPreferences prefs; static public String fontPref; //you can make it an int or whatever you need static public String myValue; //to store new pref value /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.home); initializeStyle(); } private void initializeStyle() { prefs = PreferenceManager.getDefaultSharedPreferences(this); fontPref = prefs.getString("foobar", "hi"); //this doesn't actually change the value myValue = "This is a test"; Log.i("MyActivity", foobar); //won't show change yet } } </code></pre> <p>JAVA FILE 2: Prefernce.java</p> <pre><code>import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceManager; //... and any other imports public class Preferences extends PreferenceActivity implements OnSharedPreferenceChangeListener{ private SharedPreferences prefs; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); //add other stuff here if you need, especially if you might have some //prefs that use buttons and need to set up your onClickListener for one } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPref, String key) { Editor editor = sharedPref.edit(); if(key.equalsIgnoreCase("foobar")){ Home.fontPref = sharedPref.getString("foobar", "some value"); editor.putString("foobar", Home.myValue); //where ever or whatever new value is } editor.commit(); Log.i("PrefsActivity", foobar); //should show change now } } </code></pre> <p>Hopefully this may help you get on the right track. Of course there are many ways to do these things so, good luck hope it helps.</p>
    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. 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