Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NumberPicker doesn't work with keyboard

In activity_main.xml :

<NumberPicker
        android:id="@+id/numberPicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp" />

In MainActivity.java inside the oncreate :

NumberPicker numberPicker1 = (NumberPicker) findViewById(R.id.numberPicker1);
numberPicker1.setMinValue(1);
numberPicker1.setMaxValue(20);

When I edit the value with the keyboard, the value that I get programmatically doesn't change, but if I press + then - it works.

How can I make it work without having to press + and -?


EDIT :

I created a new Project with the code of Melih Altıntaş and it displayed a whole new numberpicker!! (The one where you slide with your finger and can't enter text). Then I compared with my real project and I saw android:theme="@android:style/Theme.NoTitleBar". I added it in the new project and then the numberpicker became the one I was used to.

like image 984
Mageek Avatar asked Nov 27 '22 04:11

Mageek


1 Answers

If anyone wants a simple workaround, just add the below code before saving the value.

numberPicker.clearFocus();
like image 88
1HaKr Avatar answered Dec 05 '22 17:12

1HaKr