简体   繁体   English

如何从另一个 Activity 更改值 ListPreference

[英]How can i change value ListPreference from another Activity

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.我有 ListPreference 的活动,我可以更改其中的任何值,但我的问题是我想在没有用户进入存在 ListPreference 的活动的情况下第一次更改 ListPreference 中的值。 First time a user enters to an app i want to save default value depend on location the user.用户第一次进入应用程序时,我想保存默认值取决于用户的位置。

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改其他活动的共享首选项值? - How can I CHANGE shared preferences values from another activity? 如何获取XML中定义的ListPreference的默认值? - How can I get the default value of a ListPreference as defined in the XML? 如何将 integer 值从一项活动转移到另一项活动? - How can I transfer integer value from one activity to another? 如何从另一个活动更改一个活动的背景颜色? - How do I change the background color of an activity from another activity? 如何从一个活动传递int变量值以覆盖另一个活动中的textview - How can I pass an int variable value from one activity to overwrite a textview in another activity 我如何在活动2(Android)中更改活动1中传递的对象的值 - How can i change the value of a passed object from activity one at activity two (android) 从活动中填充ListPreference内容 - Fill ListPreference contents from Activity 如何在另一个Activity中从NumberPicker获取值以显示在expendablelistview子级的textView中 - How can I get value from NumberPicker in another Activity to show on my textView in expendablelistview child 如何将 Bundle Array 值发送​​到 android 中的另一个活动? - How can i send Bundle Array value to another activity in android? 如何将数据正确地从一项活动传递到另一项活动? - how can I pass data correctly from one activity to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM