title: How to get a preference value in preference fragment
body: <p>I want to show the value of preferences in a custom preference screen. For this I need to get the values, in this case strings, within the preference fragment. In non fragments (activities) I get the values with e.g. <code>final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);</code> and get the string with <code>String phonenumber = prefs.getString("preference_name", null);</code> but in the preference fragment <code>getDefaultSharedPreferences</code> is not applicable for preference fragment.</p>
  
  <p>Any idea how to solve this?</p>
  
  <p>Here's my code snippet:</p>
  
  <pre><code>public class PreferencesFragment extends PreferenceFragment implements
      OnSharedPreferenceChangeListener {
  
  TextView tvusername, tvphonenumber;     
  
  @Override
     public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       addPreferencesFromResource(R.xml.preferences);
       getPreferenceScreen().getSharedPreferences()
              .registerOnSharedPreferenceChangeListener(this);
  
       final SharedPreferences prefs = PreferenceManager
              .getDefaultSharedPreferences(this);
  
  
      // entering preference phonenumber in text view
              String phonenumber = prefs.getString("phonenumber", null);
              ;
              tvphonenumber.setText(phonenumber);
  
      // entering preference username in text view
              String username = prefs.getString("username", null);
              ;
              tvusername.setText(username);
  
  }
  </code></pre>