preferenceactivity

How to detect if changes were made in the preferences?

让人想犯罪 __ 提交于 2019-11-27 06:51:42
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 onCreate(Bundle savedInstanceState) { SharedPreferences prefs = this.getSharedPreferences("settings",

Launch new activity from PreferenceActivity

感情迁移 提交于 2019-11-27 05:19:09
问题 Good day, friends. I have a PreferenceActivity, it is filled from XML file. When we press one item, we should launch new activity. How to do it? What should I write in XML-file or in the Java-class? 回答1: After you add preferences using addPreferencesFromResource(R.xml.preferences); find your preference that you want to set onClick using findPreference("foo_bar_pref"); and define it by casting like Preference fooBarPref = (Preference) findPreference("foo_bar_pref"); Then you can easily set its

How to add a “long click listener” to a Preference?

邮差的信 提交于 2019-11-27 04:47:24
问题 I have an PreferenceActivity where I would like to add Preferences dynamically. On a long click, these shall do something, however OnPreferenceClickListener only supports normal clicks, no long clicks. Is there a way to implement this feature, did I miss something? Thanks 回答1: See if this helps. In the event that the link dies, here is the main body of the post at that link. Note: I did not author anything below. The built-in Preference class has a method to receive clicks, onClick, but no

How to add ToolBar in PreferenceActivity?

核能气质少年 提交于 2019-11-27 04:25:40
问题 I want to add ToolBar in PreferenceActivity in my android application. I wrote the following code. public class SettingsActivity extends PreferenceActivity { SendSMS sms; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent(); android.support.v7.widget.Toolbar bar = (android.support.v7.widget.Toolbar) LayoutInflater

Android: Start Activity from preferences.xml

末鹿安然 提交于 2019-11-27 04:12:54
问题 I would like to start an Activity from a default preferences.xml, with < intent > tag. The Activities are well tested, the problem is not with that. (I'm extending PreferenceActivity in my app, so the preferences.xml is "comes" with that) Please look at the code, what's wrong? preferences.xml: .... <PreferenceCategory android:title="@string/titleEtcSetup"> <PreferenceScreen android:key="renameCourses" android:title="@string/titleRenameCourses" android:summary="@string

ListView item won't stay “selected”

风流意气都作罢 提交于 2019-11-27 03:27:43
问题 I want to change the background of a listview item when the user clicks it. Kind of like the Honeycomb settings page (Although I'm not dealing with just settings so I'm not using PreferenceActivity) I have this functionality working through a resource state selector state selector except for the cases when clicking on the listview menu changes the linear layout to the right of the listview (sort of a split screen view). I'm guessing the listview looses focus so state_pressed is no longer true

Android- deprecated method warning regarding PreferenceActivity

浪子不回头ぞ 提交于 2019-11-27 02:45:30
问题 When I attempt to follow Android's Developer guides and tutorials for creating a Settings Activity using Preferences, I receive warnings such as: "The method addPreferencesFromResource(int) from the type PreferenceActivity is deprecated" for both of these lines in the code: getPreferenceManager().setSharedPreferencesName(PREFS_NAME); addPreferencesFromResource(R.xml.default_values); I know these are just warnings, but I was wondering if they will cause any issues, now or in the future, when I

How to add Action Bar from support library into PreferenceActivity?

让人想犯罪 __ 提交于 2019-11-26 19:18:48
Action Bar compatibility has been added into support library, revision 18. It now has ActionBarActivity class for creating activities with Action Bar on older versions of Android. Is there any way to add Action Bar from support library into PreferenceActivity ? Previously I used ActionBarSherlock and it has SherlockPreferenceActivity . EDIT: In appcompat-v7 22.1.0 Google added the AppCompatDelegate abstract class as a delegate you can use to extend AppCompat's support to any activity. Use it like this: ... import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatDelegate

PreferenceActivity Android 4.0 and earlier

孤街醉人 提交于 2019-11-26 18:23:12
Trying the different preference activities in the ApiDemos for Android 4.0, I see in the code that some methods are deprecated in PreferencesFromCode.java, for example. So my question is: if I use PreferenceFragment, will it work for all version or only 3.0 or 4.0 and up? If so, what should I use that works for 2.2 and 2.3 as well? Leo PreferenceFragment will not work on 2.2 and 2.3 (only API level 11 and above). If you want to offer the best user experience and still support older Android versions, the best practice here seems to be to implement two PreferenceActivity classes and to decide at

Android: Unable to find explicit activity class… startActivity from a PreferenceActivity

萝らか妹 提交于 2019-11-26 14:43:38
问题 I'm trying to start a new Activity from a PreferenceActivity. However, it fails with "Unable to find explicit activity class. Have you declared this activity in your AndroidManifest.xml?" Well, yeah, I declared it: <application [......] android:debuggable="true"> <activity android:name=".AlarmSettings" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>