Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Numberpicker default value not coming

When the numberpicker is loaded, the default value is not appearing on the screen until touched.

Once touched, everything works fine.Any help appreciated.

Also if the formatter is removed, it works fine.

enter image description here

dialog.xml

<NumberPicker
    android:id="@+id/number_picker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     />

<Button
    android:id="@+id/apply_button"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/number_picker"
    android:text="@string/ok_string" />

Here is the activity code:

final NumberPicker np = (NumberPicker) d.findViewById(R.id.number_picker);
        np.setMaxValue(50);
        np.setMinValue(0);
        np.setWrapSelectorWheel(true);
        np.setOnValueChangedListener(this);
        np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);

        np.setFormatter(new NumberPicker.Formatter() {
            @Override
            public String format(int i) {
                if (i == 25)
                    return "0";
                else
                    return String.valueOf(i - 25);
            }
        });
        np.setValue(25);

Thanks in advance

like image 558
Renjith Avatar asked Dec 07 '14 14:12

Renjith


1 Answers

@Renjith

Thank for the link, but I think you should link the code or even paste it here. https://code.google.com/p/android/issues/detail?id=35482#c9

Field f = NumberPicker.class.getDeclaredField("mInputText");
f.setAccessible(true);
EditText inputText = f.get(mPicker);
inputText.setFilters(new InputFilter[0]);
like image 148
user1686407 Avatar answered Oct 20 '22 12:10

user1686407