Skip to content

Commit a1410e6

Browse files
committed
NumberPicker should adjust min and max when displayed values are set.
1. The BumberPicker exposes APIs for settings displayed values for the selected numbers. If the min and max value of the picker are less then the length of the new displayed values array, i.e. they are out of bounds, the NumberPicker crashes. bug:7254000 Change-Id: I182e30216ef28c98d6541f9c985b43c8179dec76
1 parent 8c832e9 commit a1410e6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

core/java/android/widget/NumberPicker.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,14 @@ public void setDisplayedValues(String[] displayedValues) {
13611361
// Allow text entry rather than strictly numeric entry.
13621362
mInputText.setRawInputType(InputType.TYPE_CLASS_TEXT
13631363
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
1364+
// Make sure the min, max, respect the size of the displayed
1365+
// values. This will take care of the current value as well.
1366+
if (getMinValue() >= displayedValues.length) {
1367+
setMinValue(0);
1368+
}
1369+
if (getMaxValue() >= displayedValues.length) {
1370+
setMaxValue(displayedValues.length - 1);
1371+
}
13641372
} else {
13651373
mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
13661374
}

0 commit comments

Comments
 (0)