I was developing an android application where I needed to ask for user input specifically their height. Was there an elegant way of getting the user height without having 2 textboxes (1 for ft. and the other for inches)? I was hoping for maybe some type of scroller that can scroll through different heights.
CodePudding user response:
You can use an Alert Dialog with two Number Pickers. Here is a sample example of Months picker
XML will be like this
<NumberPicker
android:id="@ id/pickerMonth"
android:theme="@style/AppTheme.Picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp" />
and you can set values in the picker in the following way
binding.pickerMonth.run {
minValue = 0
maxValue = 11
value = cal.get(Calendar.MONTH)
displayedValues = arrayOf(
"Jan", "Feb", "Mar", "Apr", "May", "June", "July",
"Aug", "Sep", "Oct", "Nov", "Dec"
)
}