Skip to content

08 DigitPickerPreference

Michael Rapp edited this page Dec 29, 2017 · 2 revisions

The preference, which is provided by the class DigitPickerPreference is very similar to the preference, which has been discussed in the previous section. It also allows to choose a decimal number by using a NumberPicker widget. The difference is, that each digit of the number can be chosen individualy by using several NumberPicker widgets.

8.1 Getter and setter methods

The following getter and setter methods are provided in order to specify the properties of a DigitPickerPreference programmatically. The methods of the base class DialogPreference can be used as well.

Getter and setter methods Description Default value Restrictions
getNumber():int setNumber(int):void Returns or sets the currently persisted number of the preference. If a number is set, it is instantly persisted. 0 The number must be at least the minimum number and at maximum the maximum number.
isInputMethodUsed():boolean useInputMethod(boolean):void Returns or sets, whether it is possible to enter a number by using the keyboard, or not. false none
isSelectorWheelWrapped():boolean wrapSelectorWheel(boolean):void Returns or sets, whether the NumberPicker's selector wheel is wrapped, or not. true none
getNumberOfDigits():int setNumberOfDigits(int):void Returns or sets the number of digits of the numbers, the preference allows to choose. 4 The number of digits must be at least 1.
getMaxNumber():int setMaxNumber(int):void Returns or sets the maximum number, the preference allows to choose. 10 The maximum number must be greater than the minimum number.
getUnit():CharSequence setUnit(CharSequence):void setUnit(int):void Returns or sets the unit, which is appended to the preference's currently chosen number for textual representation. It the unit is set to null, no unit is appended. null none

8.2 XML attributes

As an alternative to the setter methods, which have been shown in the previous section, various XML attributes can be used. The following attributes are available.

XML attribute Description Format
android:defaultValue The default number of the preference. integer
custom:useInputMethod Whether it should be possible to enter a number by using the keyboard, or not. boolean
custom:wrapSelectorWheel Whether the NumberPicker's selector wheel should be wrapped, or not. boolean
custom:numberOfDigits Whether the NumberPicker's selector wheel should be wrapped, or not. integer
custom:unit The unit, which is appended to the preference's current number for textual representation. If the unit is null, no unit is appended. string

Clone this wiki locally