英文:
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();
专注分享java语言的经验与见解,让所有开发者获益!
评论