Example usage for android.support.v4.preference PreferenceManager setDefaultValues

List of usage examples for android.support.v4.preference PreferenceManager setDefaultValues

Introduction

In this page you can find the example usage for android.support.v4.preference PreferenceManager setDefaultValues.

Prototype

public static void setDefaultValues(Context context, int resId, boolean readAgain) 

Source Link

Document

Sets the default values from an XML preference file by reading the values defined by each Preference item's android:defaultValue attribute.

Usage

From source file:com.github.preferencefragment.preference.LaunchingPreferences.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*/*from  ww  w .  j  a  va2  s . c o m*/
     * These preferences have defaults, so before using them go apply those
     * defaults. This will only execute once -- when the defaults are applied
     * a boolean preference is set so they will not be applied again.
     */
    PreferenceManager.setDefaultValues(this, R.xml.advanced_preferences, false);

    // Simple layout
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    setContentView(layout);

    // Create a simple button that will launch the preferences
    Button launchPreferences = new Button(this);
    launchPreferences.setText(getString(R.string.launch_preference_activity));
    launchPreferences.setOnClickListener(this);
    layout.addView(launchPreferences, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    mCounterText = new TextView(this);
    layout.addView(mCounterText, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    updateCounterText();
}