android-preferences

Save value from custom Preference

大兔子大兔子 提交于 2019-12-02 19:02:10
问题 I have created a new preference which directly extends from CheckboxPreference . In this class I added a simple new boolean value. My question now is how I have to store this new value. If a user clicks a normal CheckboxPreference the value is stored automaticly in the preferences. I want that this happens also with my new value. For this I think I have to overwrite a method but I do not know which of them. Also I have two boolean values now (checked and my own) so I have to build a logic or

ListPreference text color

╄→尐↘猪︶ㄣ 提交于 2019-12-02 16:51:34
问题 I'm having a hard time trying to style a ListPreference. I've applied a main theme which declares a preferenceTheme and both of them link to a dialogTheme (and alertDialogTheme respectively). It works except that the text color of the items doesn't change - but the color of all other texts does. I cannot rely on a workaround because I'm using the v7 preferences and thus cannot override the dialog methods in a custom class. For me it looks like the rows ignore the text color value, but maybe

ListPreference text color

帅比萌擦擦* 提交于 2019-12-02 11:43:44
I'm having a hard time trying to style a ListPreference. I've applied a main theme which declares a preferenceTheme and both of them link to a dialogTheme (and alertDialogTheme respectively). It works except that the text color of the items doesn't change - but the color of all other texts does. I cannot rely on a workaround because I'm using the v7 preferences and thus cannot override the dialog methods in a custom class. For me it looks like the rows ignore the text color value, but maybe someone else has a solution for this. Otherwise this might be a bug? Main style: <style name="AppTheme"

Button in preference file

一笑奈何 提交于 2019-12-02 09:50:09
I have set the two buttons in preference.xml file. I want to go to main activity when I click the "ok" button. So for that code is where to write? You can set an onPreferenceClickListener in your PreferenceActivity. in preference xml : <Preference android:title="Preference Button" android:summary="This works almost like a button" android:key="mypref" /> in preferences activity : public class Preferences extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); // Get the custom

Send data from App to Widget

本秂侑毒 提交于 2019-12-02 06:22:54
问题 I am stuck in a particular scenerio. I need to get my widget updated as soon as the user update the time from the app. I did try Broadcast by sending the data thorugh Intent Extras but fail to do so. Currently, I have my data in AppWidgetProvider and I need to send this data to service public class CountdownWidget extends AppWidgetProvider { // SharedPreferences userDefaults; // update rate in milliseconds public static final int UPDATE_RATE = 1800000; // 30 minute public static String

ListPreferences without any radio buttons?

雨燕双飞 提交于 2019-12-02 05:04:27
I want to create a ListPreference in my PreferenceActivity. When a ListPreference is clicked, I get a dialog box with a listview. Each row in list view has a text field and a radio button. I do not want this radio button and also on clicking list item, I want to fire an intent that opens browser? Any idea how to go about it? If i extend DialogPreference then how to handle onClicks? Like onListClickListener will work? OR If i extend ListPreference what are the functions i need to override? This is possible when you are customizing preferences.When you are using only Preference ,it works like a

android SharedPreferences null keys, values and sets<?> - corner cases

时光毁灭记忆、已成空白 提交于 2019-12-02 02:08:04
问题 Been extensively testing the SharedPreferences framework. While most works as one would expect I run across some cases where I wonder what's the reasoning behind them. I give some tests all of which pass - their common set up is : Context ctx; SharedPreferences prefs; Editor ed; protected void setUp() throws Exception { super.setUp(); ctx = getContext(); prefs = PreferenceManager.getDefaultSharedPreferences(ctx); ed = prefs.edit(); } protected void tearDown() throws Exception { if (ed != null

How to open a new PreferenceFragment from current one, using the new Android-X API?

对着背影说爱祢 提交于 2019-12-01 19:27:58
Background On previous versions of support library, we could use headers in order to have a main-menu screen of settings, that each would open a new settings screen (fragment) . The problem Now headers are gone (as written here ) for some time, and I think it became worse on android-x : One thing you’ll note isn’t in here is preference headers and you’d be totally right. However, that doesn’t mean a single list of preferences need to span a 10” tablet screen. Instead, your Activity can implement OnPreferenceStartFragmentCallback ( link ) to handle preferences with an app:fragment attribute or

usage of findviewbyid in preferenceactivity

為{幸葍}努か 提交于 2019-12-01 15:07:03
问题 I have a preference screen and i am specifying a layout resource using the android:layout attribute. In the preference activity i am using/inflating the preference using addPreferencesFromResource from onCreate method. Inside the layout i have few textviews and buttons. The problem is i am unable to find any of the textviews, checkboxes and buttons using findViewById method ! Every result for findViewById returns null. EDIT : I need to attach a listener to the checkbox. Can anyone please help

Changing language in run time with Preferences [android]

寵の児 提交于 2019-12-01 14:05:11
I read a few times the official guide for this, and many other stuff, like questions on this site but I cant make mine work 100% As of right now if I change the language in my list preference, the activity (SettingsActivity) will not update itself (like 1 out of 20 times, somehow it will, no idea why). After I press the back button, my MainActivity did not update either. But all my other activitys always show the correct language, and if I go back to the SettingsActivity it will be okay, same with the MainActivity, if I restart the app. Relevant Parts: MainActivity: public class MainActivity