I created a user preference by following the instructions here.
http://developer.android.com/guide/topics/ui/settings.html#Custom
DialogPreference extension
Everything works, but I have some questions that I would like to understand.
First question:
I traced all the methods and the constructor, and I see that the onGetDefaultValue method is called before calling the constructor (MyCustomPreference (context context, AttributeSet attrs)) How is this possible?
Second question:
In the example they do
@Override
protected Object onGetDefaultValue(TypedArray a, int index) {
return a.getInteger(index, DEFAULT_VALUE);
}
and say
the method arguments provide everything you need: an array of attributes and the position of the android index: defaultValue, which you should get. The reason you should implement this method to extract the default value from an attribute is because you must specify a local default value for the attribute in case the value is undefined.
So, do you need to set the default value in two different places (in java code and in preferences.xml)? I think this is a little strange.
Third question:
This is not a question directly related to the onGetDefaultValue method. How is it that the a.getInteger method (index, DEFAULT_VALUE); default value required, but a.getString (index) not?
thank
source
share