Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NumberPicker wraps values when displayed values are changed

I have an android Dialog with a 3 numberpickers inside. Changing the 3rd picker triggers a change in the displayed values of the first 2 pickers. However I've noticed when I change the displayed values, and call

setWrapSelectorWheel(false)

it still shows the new values as wrapped visually (I can see the last value above the first one).

If I touch the picker it suddenly snaps into non wrap selector wheel. What's odd is I call

getWrapSelectoWheel()

after setting the displayed values and it returns false... just like I set it. But visually it's wrong.

Any ideas what's going on?

Many thanks!

like image 869
Prometheus3k Avatar asked May 24 '13 12:05

Prometheus3k


1 Answers

I found a solution, Daniel was on the right track, however it appears that initializeSelectorWheelIndices is actually a bad thing once you've already set your values. Because of this, you need to call setMinValue and setMaxValue BEFORE you set your values. However, if you already have an array set on your picker, if you call setMaxValue with a higher value than the current array, it will give you a ArrayIndexOutOfBounds exception.

The solution then is to clear the old display values, set your max value, then you can call setWrapSelectorWheel and setDisplayValues:

public void updatePickerValues(String[] newValues){
  picker.setDisplayedValues(null);
  picker.setMinValue(0);
  picker.setMaxValue(newValues.length -1);
  picker.setWrapSelectorWheel(false);
  picker.setDisplayedValues(newValues);
}
like image 74
Gabriel Avatar answered Sep 20 '22 06:09

Gabriel