ShawnLin013 / NumberPicker

:slot_machine: The android library that provides a simple and customizable NumberPicker.
MIT License
1.07k stars 240 forks source link

wrapSelectorWheel display glitch #111

Open dvkch opened 5 years ago

dvkch commented 5 years ago

First of all, thanks for this library, I spent hours looking for something like this and it is great! That being said I have an issue with wrapSelectorWheel.

I use the NumberPicker to display a dynamic list of strings and wrapSelectorWheel is only applied after I the selected item has changed from user scrolling. Initially it shows a wrapped wheel, which can't be scrolled up, and after the user scrolls the wrapped items disappear. They reappear again after I change the inputs.

Here is the layout part:

        <com.shawnlin.numberpicker.NumberPicker
            android:id="@+id/optionsPicker"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            app:np_wheelItemCount="5"
            app:np_textSize="17sp"
            app:np_selectedTextSize="18sp"
            app:np_textColor="@color/mediumGray"
            app:np_selectedTextColor="@color/darkerBlue"
            app:np_dividerColor="@color/lightGray"
            app:np_dividerDistance="30dp"
            app:np_dividerThickness="1dp"
            />

Here is the code changing the inputs:

    optionsPicker.minValue = 0
    optionsPicker.maxValue = options.size - 1
    optionsPicker.displayedValues = options.toTypedArray()
    optionsPicker.value = 0
    optionsPicker.wrapSelectorWheel = false

I saw other issues on this and tried setting the property after I change the min/max values but the behaviour persists.

philippeauriach commented 5 years ago

Seeing this as well. When changing the max Value, wheel appear as wrapped until scrolled.

veritas1 commented 5 years ago

I had the same issue. This can be fixed though, if you place optionsPicker.wrapSelectorWheel = false AFTER optionsPicker.maxValue = options.size - 1 and BEFORE optionsPicker.value = 0.

It has to be after setMaxValue() as that method overwrites the mWrapSelectorWheel flag.

dvkch commented 5 years ago

That fixed it. Maybe what's done in setValue() that causes the view to refresh could also be done in setWrapSelectorWheel to circumvent this particular ordering?

anudeepreddygopu commented 4 years ago

This didn't fix my issue. I still get it when the values are refreshed.

wildanka commented 4 years ago

@anudeepreddygopu I got the same issue, but I got something..

if you still experience the same problem after following this

I had the same issue. This can be fixed though, if you place optionsPicker.wrapSelectorWheel = false AFTER optionsPicker.maxValue = options.size - 1 and BEFORE optionsPicker.value = 0.

It has to be after setMaxValue() as that method overwrites the mWrapSelectorWheel flag.

make sure that you already set app:np_wheelItemCount or via java/kotlin code. that fixed my problem