package com.example.android.sunshine2;

import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;

public class SettingsActivity extends AppCompatActivity implements Preference.OnPreferenceChangeListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Add 'general' preferences, defined in the XML file
        // TODO: Add preferences from XML

        // For all preferences, attach an OnPreferenceChangeListener so the UI summary can be
        // updated when the preference changes.
        // TODO: Add preference
    }

    /**
     * Attaches a listener so the summary is always updated with the preference value.
     * Also fires the listener once, to initialize the summary (so it shows up before the value
     * is changed.)
     */
    private void bindPreferenceSummaryToValue(Preference preference) {
        // Set the listener to watch for value changes.
        preference.setOnPreferenceChangeListener(this);

        // Trigger the listener immediately with the preference's
        // current value.
        onPreferenceChange(preference,
            PreferenceManager
                .getDefaultSharedPreferences(preference.getContext())
                .getString(preference.getKey(), ""));
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object value) {
        String stringValue = value.toString();

        if (preference instanceof ListPreference) {
            // For list preferences, look up the correct display value in
            // the preference's 'entries' list (since they have separate labels/values).
            ListPreference listPreference = (ListPreference) preference;
            int prefIndex = listPreference.findIndexOfValue(stringValue);
            if (prefIndex >= 0) {
                preference.setSummary(listPreference.getEntries()[prefIndex]);
            }
        } else {
            // For other preferences, set the summary to the value's simple string representation.
            preference.setSummary(stringValue);
        }
        return true;
    }

}

@@ -180,23 +180,24 @@
 eference
-Manager
+Activity
 ;%0D%0Aimpor
@@ -210,40 +210,36 @@
 oid.
-support.v7.app.AppCompatActivity
+preference.PreferenceManager
 ;%0D%0A%0D
@@ -281,17 +281,18 @@
 nds 
-AppCompat
+Preference
 Acti
@@ -532,38 +532,28 @@
 le%0D%0A        
-// TODO: Add p
+addP
 references f
@@ -554,17 +554,41 @@
 nces
- from XML
+FromResource(R.xml.pref_general);
 %0D%0A%0D%0A
@@ -743,31 +743,92 @@
     
-// TODO: Add preference
+bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_location_key)));
 %0D%0A  

add settings options