Code example for EditTextPreference

Methods: getContextgetSharedPreferencessetEnabledsetSummary

0
 
public class ApplicationPreferenceActivity extends PreferenceActivity {
	 
	@SuppressWarnings("unused") 
	private RecentVideoRefreshPrefUpdater recentTvRefreshPrefUpdater;
	private PreferenceChangedListener preferenceChangedListener;
	private OnPreferenceChangeListener updateUsernameSummary = new OnPreferenceChangeListener() {
		public boolean onPreferenceChange(Preference preference, Object newValue) { 
			final EditTextPreference pref = (EditTextPreference)findPreference("username_preference"); 
			pref.setSummary((String)newValue); 
			return true; 
		}}; 
 
	 
	@Override 
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.layout.settings_pre_v11);
		setUsername(); 
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
		preferenceChangedListener = new PreferenceChangedListener(this);
		prefs.registerOnSharedPreferenceChangeListener(preferenceChangedListener);