I want to be able to create a Dialog that allows the user to pick a number from a specified range.
I know that there are existing widgets(like those from quietlycoding and the one by SimonVT) that already does this but I'm having hard time integrating those properly into my application. Also, those are primarily widgets. I want something that is very similar to the one in the android developers page tutorials.
I also checked the documentation for the NumberPicker and it said to go check the TimePicker and DatePicker for examples but they only show how to use Time and Date pickers and I'm having a hard time feeling my way around the code and trying to convert the Time Picker to just a normal Number Picker. Does anyone have any idea where to start? I've been looking for solutions for the last 3 hours to no avail.
For kotlin lovers.
and number_picker_dialog.xml
I have made a small demo of NumberPicker. This may not be perfect but you can use and modify the same.
activity_main.xml
dialog.xml
Edit:
under res/values/dimens.xml
Consider using a Spinner instead of a Number Picker in a Dialog. It's not exactly what was asked for, but it's much easier to implement, more contextual UI design, and should fulfill most use cases. The equivalent code for a Spinner is:
To show
NumberPicker
inAlertDialog
use this code :number_picker_dialog.xml
A Simple Example:
layout/billing_day_dialog.xml
NumberPickerActivity.java
AndroidManifest.xml : Specify theme for the activity as dialogue theme.
Hope it will help.