preferenceactivity

Skip the headers in PreferenceActivity when there's only one header

笑着哭i 提交于 2019-11-28 20:04:52
问题 I added preference-headers to my app so that the preference screen would not look broken on Honeycomb and tablet sized ICS. However, I only have one header at the moment so you have to click through a header screen with only one entry on phone sized devices. Is there an easy way to tell android to skip the header screen when there's only one header, but to still show it on large screens? It seems that the stock Contacts app does this successfully but I've browsed through its source and can't

PreferenceActivity: save value as integer

江枫思渺然 提交于 2019-11-28 16:04:42
Using a simple EditTextPreference in my preferences activity: <EditTextPreference android:key="SomeKey" android:title="@string/some_title" android:summary="..." android:numeric="integer" android:maxLength="2" /> Is there a way that this configuration value would be saved as integer? Seems now it just allows to enter numbers, but the value is still saved as string: Calling: SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); int value = preferences.getInt("SomeKey", -1); throws me java.lang.ClassCastException: java.lang.String , and: SharedPreferences

Preferences without deprecated methods

家住魔仙堡 提交于 2019-11-28 12:14:34
I'm trying to (correctly) implement a preferences screen, but the problem is that all the methods used to read preferences from xml files are deprecated (or I just don't recognize them). The official sample code on the dev site ( PreferenceActivity ) uses deprecated methods. Has anyone found out a way to implement a preferences screen with an xml file but without using either: addPreferencesFromResource(int) or findPreference(CharSequence)? Or have the methods just been marked deprecated without implementing the alternative yet? EDIT: Developing for Android version 2.1 Why its deprecated and

ListView item won't stay “selected”

你。 提交于 2019-11-28 10:12:08
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. <item android:state_pressed="true"> <shape > <solid android:color="@color/blue1" /> </shape> </item>

getActionBar() returns null in PreferenceActivity (AppCompat-v7 21)

北慕城南 提交于 2019-11-28 08:59:11
I have implemented DoneBar (two buttons in actionbar) in PreferenceActivity as provided in v20 sdk samples, but after updating SDK and AppCompat to version 21 my app crashes at java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayOptions(int, int)' on a null object reference That is because getActionBar() returns null. And There is no getSupportActionBar() as in ActionBarActivity . So my question is how to get that actionbar object in PreferenceActivity so I could apply custom view on it? SOLVED After some research I managed to solve this

Launch new activity from PreferenceActivity

£可爱£侵袭症+ 提交于 2019-11-28 04:21:51
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? faradaj 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 onClick using fooBarPref.setOnPreferenceClickListener (new OnPreferenceClickListener()){...} You

Android: Start Activity from preferences.xml

时间秒杀一切 提交于 2019-11-28 03:45:55
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/textRenameDisplayedCoursesNames"> <intent android:action="android.intent.action.VIEW" android:targetPackage="my.notifier.ui"

Why won't Fragment retain state when screen is rotated?

狂风中的少年 提交于 2019-11-28 03:42:04
I've been having some trouble getting some custom DialogPreference subclasses inside a PreferenceFragment to remain visible when the screen is rotated. I don't experience this problem when using a PreferenceActivity, so I don't know whether it's an Android bug or a problem with my code, but I'd like someone to confirm whether they are having the same experience. To test this, first create a preference screen containing at least one DialogPreference (it doesn't matter which subclass). Then display it in a PreferenceActivity. When you run your app, press on the DialogPreference so that it's

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

早过忘川 提交于 2019-11-27 09:29:40
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> <activity android:name=".FlashLightActivity"></activity> <receiver android:name="AlarmReceiver" android

Preferences without deprecated methods

最后都变了- 提交于 2019-11-27 06:54:49
问题 I'm trying to (correctly) implement a preferences screen, but the problem is that all the methods used to read preferences from xml files are deprecated (or I just don't recognize them). The official sample code on the dev site (PreferenceActivity) uses deprecated methods. Has anyone found out a way to implement a preferences screen with an xml file but without using either: addPreferencesFromResource(int) or findPreference(CharSequence)? Or have the methods just been marked deprecated