android-preferences

Non Deprecated findPreference() Method? - Android

陌路散爱 提交于 2019-12-17 10:38:23
问题 I want to detect when a Preference contained in a ListView gets clicked, so that I can launch an intent to manage that selection. I would have done like this in my layout XML file: <Preference android:title="About" android:key="myKey"></Preference> And the following in my java code: Preference myPref = (Preference) findPreference("myKey"); myPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { //open browser or intent

Dynamic ListPreference in android

筅森魡賤 提交于 2019-12-17 10:19:35
问题 How to generate dynamic listPreference in android? I want to get all wifi access points and make a list using in preference Activity(i.e. make a list using listpreference). How to do this? 回答1: Every XML element in Android can be created programmatically as the element name is also a Java class. Hence you can create a ListPreference in code: CharSequence[] entries = { "One", "Two", "Three" }; CharSequence[] entryValues = { "1", "2", "3" }; ListPreference lp = new ListPreference(this); lp

In android is there any way to preserve SharedPreferences after an uninstall

人走茶凉 提交于 2019-12-17 09:33:35
问题 I am keeping some application meta data in SharedPreferences . Whenever I uninstall the application and reinstall it, the SharedPreferences are deleted. Is there any way to get that to remain, so that if the user does an uninstall and reinstall, they can recover their old data? 回答1: You should add a BackupAgentHelper to your app. Together with the SharedPreferenceBackupHelper , it backups the SharedPreferences to the cloud (if the device supports it). When the app is reinstalled the data is

How to detect if changes were made in the preferences?

心不动则不痛 提交于 2019-12-17 08:48:05
问题 I have a class that extends PreferenceActivity and shows the preference screen of my app. Is it possible to check if any changes were made to the preferences? This helps... http://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html Other related post: SharedPreferences.onSharedPreferenceChangeListener not being called consistently public class PreferenceClass extends PreferenceActivity { OnSharedPreferenceChangeListener listener; public void

How to detect if changes were made in the preferences?

痞子三分冷 提交于 2019-12-17 08:47:45
问题 I have a class that extends PreferenceActivity and shows the preference screen of my app. Is it possible to check if any changes were made to the preferences? This helps... http://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html Other related post: SharedPreferences.onSharedPreferenceChangeListener not being called consistently public class PreferenceClass extends PreferenceActivity { OnSharedPreferenceChangeListener listener; public void

How to detect if changes were made in the preferences?

99封情书 提交于 2019-12-17 08:47:35
问题 I have a class that extends PreferenceActivity and shows the preference screen of my app. Is it possible to check if any changes were made to the preferences? This helps... http://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html Other related post: SharedPreferences.onSharedPreferenceChangeListener not being called consistently public class PreferenceClass extends PreferenceActivity { OnSharedPreferenceChangeListener listener; public void

Misbehavior when trying to store a string set using SharedPreferences

点点圈 提交于 2019-12-17 03:03:12
问题 I'm trying to store a set of strings using the SharedPreferences API. Set<String> s = sharedPrefs.getStringSet("key", new HashSet<String>()); s.add(new_element); SharedPreferences.Editor editor = sharedPrefs.edit(); editor.putStringSet(s); edit.commit() The first time I execute the code above, s is set to the default value (the just created end empty HashSet ) and it is stored without problems. The second and next times I execute this code, a s object is returned with the first element added.

Misbehavior when trying to store a string set using SharedPreferences

无人久伴 提交于 2019-12-17 03:03:08
问题 I'm trying to store a set of strings using the SharedPreferences API. Set<String> s = sharedPrefs.getStringSet("key", new HashSet<String>()); s.add(new_element); SharedPreferences.Editor editor = sharedPrefs.edit(); editor.putStringSet(s); edit.commit() The first time I execute the code above, s is set to the default value (the just created end empty HashSet ) and it is stored without problems. The second and next times I execute this code, a s object is returned with the first element added.

CheckBoxPreference with additional Button?

China☆狼群 提交于 2019-12-14 03:12:13
问题 I'd like to show an additional button in a CheckBoxPreference . I've managed this by subclassing CheckBoxPreference and a custom layout (using this code as a basis). However, I struggle to add an OnClickListener to this button in my PreferenceActivity . I've tried using a global OnClickListener -variable in the class extending CheckBoxPreference as well as adding a getView() -method to the PreferenceActivity that is supposed to return the Preference's view (to be able to use findViewById(R.id

How to open a nested child PreferenceScreen in Android

巧了我就是萌 提交于 2019-12-13 13:07:10
问题 I have a PreferenceScreen that is defined in XML that serves all the preferences for my application. This PreferenceScreen also has a child PreferenceScreen nested within it. My implementing class is called PreferencesActivity. I know I can open the main Preferences window via startActivity(new Intent(this, PreferencesActivity.class)); but how do I go about opening the child PreferenceScreen via an Intent? 回答1: i researched a while on this topic for my project Theft Aware (http://www