I have been researching Android Pickers as described here.
There are pickers for time, date, and number fields but, much to my surprise, I discovered there is no generic picker for basic strings.
I have found several resources discussing how to re-purpose the NumberPicker
to use strings as follows:
Android picker widget for arbitrary strings
and
https://github.com/hotchemi/StringPicker/blob/master/library/src/main/java/hotchemi/stringpicker/StringPicker.java
These look promising, but my end goal is to have my string picker fit within a panel on my main view instead of popping over the view. I need to do this because the top of my view has an object that has gets modified based on what is chosen in the picker and hence needs to be displayed in real-time to show how different values for a given property would affect its look.
Is there any way to do this?
You just need to use NumberPicker
without any library you can implement it
I also had the same problem and I found a solution for it. I used NumberPicker
like this and it works very well.
In picker_layout add number picker and show that layout on animation on main layout.
And in your class use it ...
<NumberPicker
android:id="@+id/numberPicker1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
numberPicker1= (NumberPicker) findViewById(R.id.numberPicker1);
final String genders[] = { "unassessed", "Skipped", "Incorrect", "Correct", "1 mark" };
numberPicker1.setMinValue(0);
numberPicker1.setMaxValue(genders.length - 1);
numberPicker1.setDisplayedValues(genders);
numberPicker1.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
NumberPicker.OnValueChangeListener myValChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
btnBar.setText("Value: " + genders[newVal]);
}
};
numberPicker1.setOnValueChangedListener(myValChangedListener);
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