I had the same problem and fixed it by persisting the value in the
onSetInitialValue method. The javadoc says: If restorePersistedValue is
false, you should set the Preference value to defaultValue that is given
(and possibly store to SharedPreferences if
Your solution works perfectly for me on Gingerbread (Android 2.3.7) and
below. However, when trying on ICS (4.0+) or newer, neither the *
onSetInitialValue* or the *onGetDefaultValue* functions are ever called.
Can anyone explain why the behavior changed in ICS?
On Friday, July 27, 2012
Finally, I've found a solution to this problem!
The official documentation for the preferences activity has just been
updated.
Check out the paragraph about Building a Custom Preference
http://developer.android.com/guide/topics/ui/settings.html#Custom
You have to implemenet both of the
I just came across the same issue and can confirm the same behaviour:
*android:defaultValue* of a custom DialogPreference is *not* set
with PreferenceManager.setDefaultValues() method.
Seems like a bug?
I'm using now the solution that you proposed...
On Thursday, 13 October 2011 23:11:27
Okay, I give up.
My preference default value will be copied in the preference access code as
well:
value = sharedPref.getInt(mykey,myDirtyHardcodedDefaultValue );
If ever someone has a better solution, it will be welcome :)
Thierry.
2011/10/11 Thierry Legras tleg...@gmail.com
Hi Ibendlin,
Hi Ibendlin,
Thanks for helping me :)
I don't think the problem is in SeekBarPreference.onSetInitialValue()
function itself as it is never called (I have put a log in it to check).
There is certainly an issue somewhere in my implementation; when
setDefaultValues is called, only SeekBarPreference
it took me a few weeks to get that right. here's my example for a boolean
value. And yes, .setDefaultValues is actually working, despite what you may
think :-/
@Override
protected void onSetInitialValue(boolean restoreValue, Object
defaultValue) {
boolean temp = restoreValue ?
7 matches
Mail list logo