I want to use a number picker for the purpose of getting the discount percentage from the user. once the user enters the sale price, i want a dialog box to appear asking for
This is a shorter variation of the other answers
NumberPicker picker = new NumberPicker(context);
picker.setMinValue(1);
picker.setMaxValue(50);
FrameLayout layout = new FrameLayout(context);
layout.addView(picker, new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER));
new AlertDialog.Builder(context)
.setView(layout)
.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
// do something with picker.getValue()
picker.getValue();
})
.setNegativeButton(android.R.string.cancel, null)
.show();