Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: NumberPicker doesn´t work

I added a NumberPicker to my layout and debugged my app. Now I see that the NumberPicker doesn´t work, I can´t see any "+" or "-" button and also when I click on a number on my keyboard, nothing happens.

Here´s my layout file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#99cc00"
tools:context=".Gewichtsentwicklung" >

<NumberPicker
    android:id="@+id/numberPicker1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="80dp" />

<TextView
    android:id="@+id/tvGewichtUeberschrift"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_centerHorizontal="true"
    android:textColor="@color/white"
    android:textSize="13pt"
    android:layout_alignParentTop="true"
    android:text="Aktuelles Gewicht eingeben" />

<Button
    android:id="@+id/btGewicht"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/numberPicker1"
    android:layout_marginTop="79dp"
    android:text="Gewicht speichern" />

Where´s the problem?

like image 367
user896692 Avatar asked Jun 06 '13 17:06

user896692


2 Answers

Are you actually populating the number picker with values? As shown below?

NumberPicker np = (NumberPicker) findViewById(R.id.numberPicker1);
String[] nums = new String[20];
for(int i=0; i<nums.length; i++)
       nums[i] = Integer.toString(i);

np.setMinValue(1);
np.setMaxValue(20);
np.setWrapSelectorWheel(false);
np.setDisplayedValues(nums);
np.setValue(1);
like image 125
Martin Cazares Avatar answered Sep 27 '22 19:09

Martin Cazares


the number picker does not have a + or - think of it as more of a scroll wheel. you have to set the minimum number and the maximum number for it to show anything really

setMinValue(5);
setMaxValue(120);

if you click the top portion of the picker it increases the number, if you click the bottom portion of the picker it decreases the number

like image 39
tyczj Avatar answered Sep 27 '22 17:09

tyczj