Skip to content

Commit 7caffbc

Browse files
sganovAndroid (Google) Code Review
authored andcommitted
Merge "NumberPicker should not throw an exception if no enough values for wrapping."
2 parents 9f46b11 + 3f9c9ea commit 7caffbc

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

api/current.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26676,6 +26676,7 @@ package android.widget {
2667626676
method public void setOnValueChangedListener(android.widget.NumberPicker.OnValueChangeListener);
2667726677
method public void setValue(int);
2667826678
method public void setWrapSelectorWheel(boolean);
26679+
field public static final int SELECTOR_WHEEL_ITEM_COUNT = 5; // 0x5
2667926680
}
2668026681

2668126682
public static abstract interface NumberPicker.Formatter {

core/java/android/widget/NumberPicker.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
@Widget
7171
public class NumberPicker extends LinearLayout {
7272

73+
/**
74+
* The number of items show in the selector wheel.
75+
*/
76+
public static final int SELECTOR_WHEEL_ITEM_COUNT = 5;
77+
7378
/**
7479
* The default update interval during long press.
7580
*/
@@ -1137,14 +1142,17 @@ public boolean getWrapSelectorWheel() {
11371142
* items shown on the selector wheel) the selector wheel wrapping is
11381143
* enabled.
11391144
* </p>
1140-
*
1145+
* <p>
1146+
* <strong>Note:</strong> If the number of items, i.e. the range
1147+
* ({@link #getMaxValue()} - {@link #getMinValue()}) is less than
1148+
* {@link #SELECTOR_WHEEL_ITEM_COUNT}, the selector wheel will not
1149+
* wrap. Hence, in such a case calling this method is a NOP.
1150+
* </p>
11411151
* @param wrapSelectorWheel Whether to wrap.
11421152
*/
11431153
public void setWrapSelectorWheel(boolean wrapSelectorWheel) {
1144-
if (wrapSelectorWheel && (mMaxValue - mMinValue) < mSelectorIndices.length) {
1145-
throw new IllegalStateException("Range less than selector items count.");
1146-
}
1147-
if (wrapSelectorWheel != mWrapSelectorWheel) {
1154+
final boolean wrappingAllowed = (mMaxValue - mMinValue) >= mSelectorIndices.length;
1155+
if ((!wrapSelectorWheel || wrappingAllowed) && wrapSelectorWheel != mWrapSelectorWheel) {
11481156
mWrapSelectorWheel = wrapSelectorWheel;
11491157
updateIncrementAndDecrementButtonsVisibilityState();
11501158
}

0 commit comments

Comments
 (0)