Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
NumberPicker should adjust min and max when displayed values are set.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sganov committed Sep 28, 2012
1 parent 8c832e9 commit a1410e6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/java/android/widget/NumberPicker.java
Expand Up @@ -1361,6 +1361,14 @@ public void setDisplayedValues(String[] displayedValues) {
// Allow text entry rather than strictly numeric entry.
mInputText.setRawInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
// Make sure the min, max, respect the size of the displayed
// values. This will take care of the current value as well.
if (getMinValue() >= displayedValues.length) {
setMinValue(0);
}
if (getMaxValue() >= displayedValues.length) {
setMaxValue(displayedValues.length - 1);
}
} else {
mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
}
Expand Down

0 comments on commit a1410e6

Please sign in to comment.