KasualBusiness / MaterialNumberPicker

A customizable Android NumberPicker that is inspired from the Material Design Guidelines
Apache License 2.0
135 stars 20 forks source link

Typing in a number with a decimal point always sets the value of the picker to its minValue #11

Open chantellosejo opened 8 years ago

chantellosejo commented 8 years ago

Easily fixed, but the inputType for the EditText allows the user to enter in numeric values with decimals. If you do this, it always sets the value to the picker's minimum value (not desired behavior).

I fixed it with this bit of code:

` private void updateTextAttributes() {

    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);

        if (child instanceof EditText) {
            try {

                Field selectorWheelPaintField = NumberPicker.class.getDeclaredField("mSelectorWheelPaint");
                selectorWheelPaintField.setAccessible(true);

                Paint wheelPaint = ((Paint) selectorWheelPaintField.get(this));
                wheelPaint.setColor(mTextColor);
                wheelPaint.setTextSize(mTextSize);

                EditText editText = ((EditText) child);
                editText.setTextColor(mTextColor);
                editText.setTextSize(pixelsToSp(getContext(), mTextSize));
                **editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL);**

                invalidate();
                break;
            } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException e) {
                e.printStackTrace();
            }
        }
    }
}`

I'll submit a pull request later if you need me to. Thanks!

StephenVinouze commented 7 years ago

Thanks for reporting @chanakin, I must admit I never use the editable mode. Added your piece of code in the library I recreated here.