PreferenceActivity用例

PreferenceActivity用例

PreferenceActivity用例

获取preference的value:

PreferenceManager.setDefaultValues(this, R.xml.preference01, false);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

String str = prefs.getString(key, defValue);

 

几个重要的属性:

Key:唯一标识.

title:显示标题(大字体显示)

summary:副标题(小字体显示)

 

监听preference:

EditTextPreference et_pre_restaurant;

et_pre_restaurant = (EditTextPreference)findPreference("name_restaurant");

et_pre_restaurant.setOnPreferenceChangeListener(this);

设置summary:

EditTextPreference et_pre_restaurant;

et_pre_restaurant = (EditTextPreference)findPreference("name_restaurant");

preTimeSleep01.setSummary("hello");

监听触发事件 :

    @Override
public boolean onPreferenceChange(Preference preference, Object object) {
// TODO Auto-generated method stub

if (preference.getKey().equals("name_restaurant")){

Toast.makeText(SystemSetActivity.this, "餐厅名称修改了", Toast.LENGTH_SHORT).show();
}
return true;
}

 

参考:

http://www.cnblogs.com/wservices/archive/2010/07/08/1773449.html



 

 

你可能感兴趣的:(PreferenceActivity用例)