preferences

How to get a preference value in preference fragment

六月ゝ 毕业季﹏ 提交于 2019-12-05 10:49:06
I want to show the value of preferences in a custom preference screen. For this I need to get the values, in this case strings, within the preference fragment. In non fragments (activities) I get the values with e.g. final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); and get the string with String phonenumber = prefs.getString("preference_name", null); but in the preference fragment getDefaultSharedPreferences is not applicable for preference fragment. Any idea how to solve this? Here's my code snippet: public class PreferencesFragment extends

How to return from preference screen to main activity?

依然范特西╮ 提交于 2019-12-05 09:57:30
I have one main activity and one preferenceActivity. On my first activity I call menu and go on preferenceActivity by calling startActivityForResult. case R.id.settings: startActivityForResult(new Intent(this, SettingsActivity.class), LAUNCH_SETTINGS); return true; Then I change my settings and want to return on main activity and see main activity with new settings applyed. In onPause() method do following (as I right understand this method will be called when I press back button, right?) @Override protected void onPause() { super.onPause(); setResult(RESULT_OK, new Intent(this, MainActivity

Android custom Preference title size comes out incorrect on some devices. What is the right place to pick it up?

非 Y 不嫁゛ 提交于 2019-12-05 06:35:35
问题 This problem turned out to be much more tricky than it first appeared as it wasn't a problem on all but a few devices. When creating a custom Preference by making it a subclass of Preference and also use a custom layout defined in an XML file in res/layout and use that layout in onCreateView() in the custom Preference it seems you completely loose the layout information the Preference-s normally have. Nothing strange with that, but if you still want a title (together with the new stuff), how

Java Swing Mac OSX Preferences Menu

被刻印的时光 ゝ 提交于 2019-12-05 04:33:58
I'm trying to add the Preferences menu to my Java Swing application and it's proving a bit of a nause. I have read many posts and articles on this and it sounds easy but... I see references to com.apple.eawt.Application in the examples I have found but when I try to import it in Eclipse Indigo I get an error: Access restriction: The type Application is not accessible due to restriction on required library /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar Any ideas? I am working on an iMac OSX 10.6 trashgod You might be able to use OSXAdapter , which "uses a reflection

How to store variables/preferences in Python for later use

半腔热情 提交于 2019-12-05 04:10:37
I'm working on a program in Python for Windows, and would like to save variables and user preferences so that I can recall them even after the program has been terminated and restarted. Is there an ideal way to do this on Windows machines? Would _winreg and the Windows registry be suited for this task? Or do I need to create some sort of database of my own? You're usually going to want to store it in a configuration folder in the "home" folder. That's easy on *nix systems, more difficult in windows, because you actually need to get the "application data" directory. This usually works for me:

onPreferenceChange method isn't called when Listpreferences changes

孤街浪徒 提交于 2019-12-05 02:42:08
I have a Preferences Activity in my code. I want to show a toast when ever user change radio button in a ListPreferences. I used this code but it does not work. :( public class PrefsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); } public void onSharedPreferenceChanged(SharedPreferences arg0, String key) { ListPreference listPreference = (ListPreference) findPreference(key); listPreference.setOnPreferenceChangeListener(new

How can I concatenate static strings with XML string resources?

試著忘記壹切 提交于 2019-12-05 02:33:45
I'm trying to combine a static "hard coded" string with one referenced from strings.xml for string array items. The goal is to have a dynamic metrics list where the number is the same for all languages, but the metrics text value may change by language, something like this: <string-array name="interval_labels"> <item>30 @string/second</item> <item>1 @string/minute</item> <item>5 @string/minute</item> <item>10 @string/minute</item> <item>15 @string/minute</item> <item>30 @string/minute</item> <item>60 @string/minute</item> </string-array> Right now, if I remove the numbers before the @string/..

Can't Control Order of String Set in Shared Preferences

耗尽温柔 提交于 2019-12-05 00:13:11
问题 This is my first stackoverflow question. I have done lot of googling on this. On Hashsets, Treesets, LinkedHashSets, Collections, Stacks (Stack class is deprecated?)... I realize I could just use SQLite but I'm trying to avoid that for the time being. I'm working on an app in Android Studio. The app deals with people, listing them and contacting them in different ways. App users can maintain and control three types of lists: recently contacted, blocked, and favorites. These lists are saved as

How to dynamically add preferences into preferences screen and bind their values?

ぐ巨炮叔叔 提交于 2019-12-04 23:36:14
问题 I'm new in Android. In my app i want to do something like this: I have a container and i want to add item dynamically to it, in one item there may be some fields, so tree would be like this: main container - item 1 --field 1 --field 2 ... --field n - item 2 --field 1 --filed 2 ....... - item n --field 1 --field 2 ... field n I want to do this using preferences, cause i need store user's info in app, but don't know how. Can you help me, please? 回答1: You need to create an xml file with an empty

starting an activity from preferences.xml

谁说胖子不能爱 提交于 2019-12-04 21:08:25
问题 I'm trying to go to the settings screen found at - android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS From an entry in my preferences activity but am having no luck. At the moment, pressing the entry just refreshes the same screen as I was on. My preferences.xml looks like this: <Preference android:title="@string/my_location_settings"> <intent android:action="android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS"> </intent> </Preference> And my manifest entry looks like this: