1 package de.example.exampletdd.fragment;
3 import android.content.SharedPreferences;
4 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
5 import android.os.Bundle;
6 import android.preference.Preference;
7 import android.preference.PreferenceFragment;
8 import de.example.exampletdd.R;
10 public class WeatherInformationPreferencesFragment extends PreferenceFragment
11 implements OnSharedPreferenceChangeListener {
14 public void onCreate(final Bundle savedInstanceState) {
15 super.onCreate(savedInstanceState);
17 // Load the preferences from an XML resource
18 this.addPreferencesFromResource(R.xml.weather_preferences);
20 String keyPreference = this.getActivity().getString(
21 R.string.weather_preferences_units_key);
22 Preference connectionPref = this.findPreference(keyPreference);
23 connectionPref.setSummary(this.getPreferenceManager()
24 .getSharedPreferences().getString(keyPreference, ""));
26 keyPreference = this.getActivity().getString(
27 R.string.weather_preferences_language_key);
28 connectionPref = this.findPreference(keyPreference);
29 connectionPref.setSummary(this.getPreferenceManager()
30 .getSharedPreferences().getString(keyPreference, ""));
34 public void onResume() {
36 this.getPreferenceManager().getSharedPreferences()
37 .registerOnSharedPreferenceChangeListener(this);
42 public void onPause() {
44 this.getPreferenceManager().getSharedPreferences()
45 .unregisterOnSharedPreferenceChangeListener(this);
49 public void onSharedPreferenceChanged(
50 final SharedPreferences sharedPreferences, final String key) {
51 String keyValue = this.getActivity().getString(
52 R.string.weather_preferences_units_key);
54 if (key.equals(keyValue)) {
55 final Preference connectionPref = this.findPreference(key);
56 connectionPref.setSummary(sharedPreferences.getString(key, ""));
59 keyValue = this.getActivity().getString(
60 R.string.weather_preferences_language_key);
61 if (key.equals(keyValue)) {
62 final Preference connectionPref = this.findPreference(key);
63 connectionPref.setSummary(sharedPreferences.getString(key, ""));