浏览 5833 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2011-04-21
最后修改:2011-04-21
package com.xxxx.xxxx.activity; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceManager; import android.preference.PreferenceScreen; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.EditTextPreference; import android.util.Log; import android.widget.Toast; import com.xxxx.xxxx.R; /** * * 个人设置 * */ public class PreferenceActivity extends android.preference.PreferenceActivity implements OnPreferenceChangeListener { private static final String TAG = "PreferenceActivity"; private Context mCtx; private SharedPreferences mPreferences; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preference); mCtx = this; mPreferences = PreferenceManager.getDefaultSharedPreferences(mCtx); } @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { preference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String key=preference.getKey(); if(key.equals("editkey")){ //动态改变summary的值 if(((String) newValue).trim().equals("")) preference.setSummary(R.string.xxxx); else preference.setSummary(getResources().getString(R.string.xxxx)+newValue); }else if(key.equals("listkey")){ preference.setSummary(getResources().getString(R.string.xxxx)+newValue); } return true; } }); return true; } }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |