如何更改首选项屏幕的TextEdit值,我希望更改MainActivity的TextEdit。我怎么能这样做?。
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
if (key.equals(PrefUserName)) {
SharedPreferences sharedPref = PreferenceManager
.getDefaultSharedPreferences(getApplication());
String textoEditTextPreference = sharedPref.getString(key,
"");
// Spinner spinner = (Spinner) findViewById(R.layout.activity_main);
//Here I want add value spinner of main activity...
// Spinner spinner = (Spinner) findViewById(R.layout.activity_main);
Toast.makeText(
getApplication(),
"New name of user: "
+ textoEditTextPreference, Toast.LENGTH_SHORT)
.show();
}
答案 0 :(得分:0)
据我所知,您的问题是: 您应该使用SharedPreference Editor
SharedPreferences.Editor prefEditor = sharedPref.edit();
prefeditor.putString(key, "");
prefeditor.commit();