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.
If anyone wants a simple workaround, just add the below code before saving the value.
numberPicker.clearFocus();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With