Git at Google

commita1410e6789ce72bc423793315a51aea8b6bad6c7[log][tgz]
authorSvetoslav Ganov <svetoslavganov@google.com>Fri Sep 28 12:35:55 2012 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>Fri Sep 28 12:40:42 2012 -0700
treed0bd359b2e71cbda65a04c973f1205f2ac7bb938
parent8c832e9f766edfc6130c3eea30e1869e2db8de26[diff]
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
diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java
index 704f6b6..4918e48 100644
--- a/core/java/android/widget/NumberPicker.java
+++ b/core/java/android/widget/NumberPicker.java
@@ -1361,6 +1361,14 @@
             // 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);
         }