I am using a number picker that I control from software to range from only 1 number to any larger number of positions. It works as expected for all numbers of positions except for 3. When I set it to 3 positions it becomes difficult to impossible to set the number picker to 2 (the 2nd in 3 possible positions). This is unexpected and I would like to know how to fix this so the number picker can be set to 2.
Code fragment to increase the number picker by 1:
// Get the maximum marker number picker value and increment in prep // for the new marker. Integer routes_num = selectMarkerNumPicker.getMaxValue(); routes_num += 1; // Add 1 to current waypoint total value for this route. int route = selectRouteNumPicker.getValue(); route_count_string[route - 1] = String.valueOf(Integer.valueOf(route_count_string[route - 1]) + 1); // Set number picker to new/last marker position. selectMarkerNumPicker.setMinValue(1); selectMarkerNumPicker.setValue(0); selectMarkerNumPicker.setMaxValue(routes_num); selectMarkerNumPicker.setValue(routes_num);Code fragment to decrement number picker by 1:
// Always delete the last Marker. Integer marker_num = selectMarkerNumPicker.getMaxValue(); marker_num -= 1; Integer route_num = selectRouteNumPicker.getValue(); // If this is the last marker in a route do not delete it. Instead tell // user to delete route. if(route_count_string[route_num - 1].equals("1")) { // This is the last marker in a route. Do not delete it. Instead tell // user to delete route. Toast.makeText(getApplicationContext(), "Can't Delete Last Marker\nDelete Route Instead", Toast.LENGTH_SHORT).show(); } else { // Set number picker to new/last marker position. selectMarkerNumPicker.setMinValue(1); selectMarkerNumPicker.setValue(0); selectMarkerNumPicker.setMaxValue(marker_num); selectMarkerNumPicker.setValue(marker_num);Also of interest:
There are about a dozen number pickers in this Android Activity. Two of these, including the one above, have their range controlled by software. But after repeated testing, only the one above behaves unexpectedly when set to have 3 items (numbers "1", "2" & "3"). Again, the number picker affected does not "snap" or has great difficulty "snapping" to the 2nd item ("2").