content: package com.myapps.documentscanner;
  
  import android.content.SharedPreferences;
  import android.os.Bundle;
  import android.preference.EditTextPreference;
  import android.preference.ListPreference;
  import android.preference.Preference;
  import android.preference.PreferenceFragment;
  import android.preference.PreferenceGroup;
  import android.preference.PreferenceScreen;
  
  /**
   * Created by ANIRUDDHA
   */
  public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          addPreferencesFromResource(R.xml.settings);
          getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
  
      }
  
      @Override
      public void onResume() {
          super.onResume();
          updatePreferenceScreen(getPreferenceScreen());
      }
  
      public void updatePreferenceScreen(PreferenceScreen screen) {
          for (int i = 0; i < screen.getPreferenceCount(); ++i) {
              Preference preference = screen.getPreference(i);
              if (preference instanceof PreferenceGroup) {
                  PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
                  for (int j = 0; j < preferenceGroup.getPreferenceCount(); ++j) {
                      Preference singlePref = preferenceGroup.getPreference(j);
                      updatePreference(singlePref, singlePref.getKey());
                  }
              } else {
                  updatePreference(preference, preference.getKey());
              }
          }
      }
  
      @Override
      public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
          updatePreference(findPreference(key), key);
      }
  
      private void updatePreference(Preference preference, String key) {
          if (preference == null) return;
          if (preference instanceof ListPreference) {
              ListPreference listPreference = (ListPreference) preference;
              listPreference.setSummary(listPreference.getEntry());
              return;
          } if (preference instanceof EditTextPreference) {
              SharedPreferences sharedPrefs = getPreferenceManager().getSharedPreferences();
              preference.setSummary(sharedPrefs.getString(key, "Default"));
          } if (preference instanceof PreferenceScreen) {
              updatePreferenceScreen((PreferenceScreen) preference);
          }
      }
  }
  