Skip to content

Commit 7018cfd

Browse files
committed
Revert "NumberPicker should adjust min and max when displayed values are set." (a.k.a. Santa is back)
This reverted change was adjusting the min and max values for the NumberPicker which is not desirable since it changes behavior and it will be possible for an app that works on the current platform to crash on an older one. Also the adjustment was not implemented correctly. Updated the documentation to clarify the reltionship between the min value, max value, and the displayed values array. Bug:7518172 This reverts commit a1410e6 Change-Id: I109f1b1f54c1e609941243cabab9241871b6b12b
1 parent 721b370 commit 7018cfd

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

core/java/android/widget/NumberPicker.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,12 @@ public int getMinValue() {
12841284
/**
12851285
* Sets the min value of the picker.
12861286
*
1287-
* @param minValue The min value.
1287+
* @param minValue The min value inclusive.
1288+
*
1289+
* <strong>Note:</strong> The length of the displayed values array
1290+
* set via {@link #setDisplayedValues(String[])} must be equal to the
1291+
* range of selectable numbers which is equal to
1292+
* {@link #getMaxValue()} - {@link #getMinValue()} + 1.
12881293
*/
12891294
public void setMinValue(int minValue) {
12901295
if (mMinValue == minValue) {
@@ -1317,7 +1322,12 @@ public int getMaxValue() {
13171322
/**
13181323
* Sets the max value of the picker.
13191324
*
1320-
* @param maxValue The max value.
1325+
* @param maxValue The max value inclusive.
1326+
*
1327+
* <strong>Note:</strong> The length of the displayed values array
1328+
* set via {@link #setDisplayedValues(String[])} must be equal to the
1329+
* range of selectable numbers which is equal to
1330+
* {@link #getMaxValue()} - {@link #getMinValue()} + 1.
13211331
*/
13221332
public void setMaxValue(int maxValue) {
13231333
if (mMaxValue == maxValue) {
@@ -1351,6 +1361,10 @@ public String[] getDisplayedValues() {
13511361
* Sets the values to be displayed.
13521362
*
13531363
* @param displayedValues The displayed values.
1364+
*
1365+
* <strong>Note:</strong> The length of the displayed values array
1366+
* must be equal to the range of selectable numbers which is equal to
1367+
* {@link #getMaxValue()} - {@link #getMinValue()} + 1.
13541368
*/
13551369
public void setDisplayedValues(String[] displayedValues) {
13561370
if (mDisplayedValues == displayedValues) {
@@ -1361,14 +1375,6 @@ public void setDisplayedValues(String[] displayedValues) {
13611375
// Allow text entry rather than strictly numeric entry.
13621376
mInputText.setRawInputType(InputType.TYPE_CLASS_TEXT
13631377
| 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-
}
13721378
} else {
13731379
mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
13741380
}

0 commit comments

Comments
 (0)