如何从另一个Activity中更改ListPreference的值

huangapple 未分类评论50阅读模式
英文:

How can i change value ListPreference from another Activity

问题

我有一个用于ListPreference的Activity,我可以在其中更改任何值,但我的问题是,我想在用户进入该Activity之前就第一次更改ListPreference中的值。当用户第一次进入应用程序时,我想根据用户的位置保存默认值。

英文:

I have Activity for ListPreference and i can change any values in it , but my question i want to change a value in ListPreference first time without the user enters to activity that there is ListPreference .
First time a user enters to an app i want to save default value depend on location the user.

答案1

得分: 0

我找到了解决方法

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(getString(R.string.settings_method_key), repear);
editor.commit();
英文:

I found the solution

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(getString(R.string.settings_method_key),repear);
        editor.commit();

huangapple
  • 本文由 发表于 2020年5月30日 04:40:52
  • 转载请务必保留本文链接:https://java.coder-hub.com/62094283.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定