ShawnLin013 / NumberPicker

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

Changing DisplayedValues can cause a crash. #158

Closed VincentSit closed 4 years ago

VincentSit commented 4 years ago

Changing DisplayedValues to a shorter array, and then changing to a longer array, will certainly cause a crash.

Add the following code to the simple to reproduce the bug.

...
// Set string values
        String[] data = {"A", "B", "C", "D", "E", "F", "G", "H", "I"};
        numberPicker.setMinValue(1);
        numberPicker.setMaxValue(data.length);
        numberPicker.setDisplayedValues(data);

        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                String[] data = {"W", "Y", "Z"};
                numberPicker.setMinValue(1);
                numberPicker.setMaxValue(data.length);
                numberPicker.setDisplayedValues(data);

                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        String[] data = {"A", "B", "C", "D", "E", "F", "G", "H", "I"};
                        numberPicker.setMinValue(1);
                        numberPicker.setMaxValue(data.length);
                        numberPicker.setDisplayedValues(data);
                    }
                }, 2000);
            }
        }, 2000);
...
ShawnLin013 commented 4 years ago

Fixed at v2.4.9.