Custom Attributes for DialogPreference

I created a new TimeDialogPreferenceone that expands DialogPreference.

In preferences.xmlI have:

<info.chrzanowski.project.preference.TimeDialogPreference
    android:key="recordTime"
    android:id="@+id/recordTime"
    android:title="title"
    android:summary="summary"
    step="5"
    />

How do I access from a class TimeDialogPreferencefor an attribute step?

+5
source share
2 answers

Attributes are passed to the constructor of your user preference:

Check the AttributeSet class for other ways to subtract a 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);
        }
    }
}
+8
source

All Articles