I'm using number picker in a dialog and want to change the scroll direction from Up to down. Which mean currently by default if i scroll up, numbers come from bottoms side but i want them to come from upside and scroll will be downwards instead of upwards. Here is my number picker Dialog Code.
private static void getMeasure(int textMsg, final BoardRect item,
final int defaultValue, final int maxValue,
final OnUIMeasureReadListener listener) {
final NumberPicker picker = new NumberPicker(
AppContext.getActivityContext());
picker.setMinValue(-1);
picker.setMaxValue(maxValue);
picker.setWrapSelectorWheel(false);
picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
// create actual dialog
final AlertDialog.Builder msgbox = new AlertDialog.Builder(
AppContext.getActivityContext());
msgbox.setCancelable(true);
msgbox.setTitle(AppContext.getActivityContext().getResources()
.getString(R.string.rect_dimen));
msgbox.setMessage(textMsg);
msgbox.setView(picker);
msgbox.setPositiveButton(AppContext.getActivityContext().getResources()
.getString(R.string.dlg_positive_btn),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
try {
listener.measureRead(picker.getValue());
} catch (Exception ex) {
}
}
});
AlertDialog dialog = msgbox.create();
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
wmlp.x = 135; // x position
wmlp.y = 0; // y position
dialog.getWindow().setAttributes(wmlp);
dialog.show();
dialog.getWindow().setLayout(350, 650);
}
I just had the same problem. I used the
setDisplayedValues()
method of theNumberPicker
class to explicitly set the values to be displayed. You can generate an array of strings that represent the string values of the numbers you want:Store that array in a field
_displayValues
and then you can call:When the
OnValueChangeListener
event is raised, usenewVal
as an index into your array:Hope that helps.