I have a number picker for minutes. Initially I set displayed values to 15minute intervals. ie, 0,15,30, 45 which means Min is 1 and max is 4. On user selecting a menu option, I want to dynamically change the same Number picker to have 5 minute intervals which means displayed values will be 0,5,10... 50,55 Min will remain 1 and max will be 12.
It works fine with initial settings for both types. However, I am getting array out of index when I try to modify the max value or displayed values. The issue occurs when changing the characteristics both ways ie 15 to 5 or 5 to 15 minute intervals.
Question is am I doing something wrong or is this not possible at all with number pickers. My sample code is below. thanks.
private void setMinsPicker(String opt) {
String[] mins15 = { "0", "15", "30", "45" };
String[] mins5 = { "0", "5", "10", "15", "20", "25", "30", "35", "40",
"45", "50", "55" };
final String[] mins;
if (opt == "15") {
mins = mins15;
} else {
mins = mins5;
}
numPickerMinutes = (NumberPicker) findViewById(R.id.pMinutes);
int ml = mins.length;
numPickerMinutes.setMinValue(1);
numPickerMinutes.setDisplayedValues(mins);
numPickerMinutes.setMaxValue(ml);
}