0

如何更改首选项屏幕的 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();
    }
4

1 回答 1

0

据我所知,您的问题是:您应该使用 SharedPreference Editor

SharedPreferences.Editor prefEditor = sharedPref.edit();
prefeditor.putString(key, "");
prefeditor.commit();
于 2014-09-22T13:36:01.280 回答