I can't seem to figure out how for a value into the numberpicker. It always shows 0 when the min and max are the same. Is there any way to ovveride it? Here is my code.
int min = cursor.getInt(cursor.getColumnIndex(RestaurantElementsTable.KEY_MIN_QUANITY));
int max = cursor.getInt(cursor.getColumnIndex(RestaurantElementsTable.KEY_MAX_QUANITY));
int defaultQuanity = cursor.getInt(cursor.getColumnIndex(RestaurantElementsTable.KEY_DEFAULT_QUANITY));
if ( max - min == 0){
((NumberPicker) view).setValue(defaultQuanity);
}else {
((NumberPicker) view).setMaxValue(max);
((NumberPicker) view).setMinValue(min);
((NumberPicker) view).setWrapSelectorWheel(false);
((NumberPicker) view).setValue(defaultQuanity);
}
By default maxValue
and minValue
in NumberPicker
is 0. So you need to set maxValue
and minValue
before using setValue
.
For example:
if ( max == min) {
((NumberPicker) view).setMaxValue(defaultQuanity);
((NumberPicker) view).setMinValue(defaultQuanity);
((NumberPicker) view).setValue(defaultQuanity);
}