I want to let the user choice an element from ArrayList<MyObjectType>
via a wheel picker that looks similar to the wheel picker that gets used to pick the day/month/year in the data picker. While the date picker obviously has three variables, I only care about having one.
What's the most straightforward way to implement such a picker?
NumberPicker is provided in Android Widgets. That is what you are looking for.
Solution
<NumberPicker
android:id="@+id/numberPicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
and in Java
NumberPicker np = findViewById(R.id.numberPicker);
String[] months3char = get3CharMonths();
np.setMaxValue(months3char.length - 1); // important
np.setDisplayedValues(months3char); // custom values
private String[] get3CharMonths() {
String[] months = new DateFormatSymbols().getMonths();
String[] months3char = new String[months.length];
for (int i = 0; i < months.length; i++) {
String month = months[i];
months3char[i] = month.length() < 3 ? month : month.substring(0, 3);
}
return months3char;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With