I've created new TimeDialogPreference
that extends DialogPreference
.
In preferences.xml
I have:
<info.chrzanowski.project.preference.TimeDialogPreference
android:key="recordTime"
android:id="@+id/recordTime"
android:title="title"
android:summary="summary"
step="5"
/>
How can I access from TimeDialogPreference
class that step
attribute ?
Custom attributes. A custom attribute is a property that you can define to describe assets. Custom attributes extend the meaning of an asset beyond what you can define with the standard attributes. You can create a custom attribute and assign to it a value that is an integer, a range of integers, or a string.
It's still possible to customise the appearance of a Preference item though. In your XML you have to declare the root element as android:id="@android:id/widget_frame , and then declare TextView as android:title and android:summary . You can then declare other elements you want to appear in the layout.
The attributes are passed to the constructor of your custom preference:
Check out the AttributeSet class for other ways to dig out the value, for example:
public TimeDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
for (int i=0;i<attrs.getAttributeCount();i++) {
String attr = attrs.getAttributeName(i);
String val = attrs.getAttributeValue(i);
if (attr.equalsIgnoreCase("step")) {
Log.i("TimeDialogPreference", "step = "+val);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With