1

I created NumberPicker but it comes up empty and I cant click anything else than textfield where is this "0" and when I do that keypad pops up. Here is picture to clarify what I mean.

Picture: enter image description here

Here is the code that I use to create dialog:

Dialog dialog = new Dialog(SettingsActivity.this);
dialog.setContentView(R.layout.draws_dialog);
dialog.show();

SettingsActivity is the activity where I create and show this dialog.

and here is the xml of my dialog:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content">

    <NumberPicker
        android:id="@+id/numberPicker1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

</RelativeLayout>

so any Idea what am I doing wrong here?

Sergio
  • 28,539
  • 11
  • 85
  • 132
Rohit Malish
  • 3,209
  • 12
  • 49
  • 67

2 Answers2

2

you should set min and max values for your NumberPicker, for example like this:

int minValue = 5;
int maxValue = 20;
int currentValue = 10;

final NumberPicker uiCapacity = findViewById(R.id.capacity);
uiCapacity.setMinValue(minValue);
uiCapacity.setMaxValue(maxValue);
uiCapacity.setValue(currentValue);
Vladimir
  • 21
  • 1
0

Your NumberPicker isn't Holo.Light styled. See this question.

Create the AlertDialog like this:

     View npView = getLayoutInflater().inflate(R.layout.number_picker_dialog, null);

     NumberPicker mPicker = (NumberPicker)npView.findViewById(R.id.npQuantity);
        mPicker.setMaxValue(100);
        mPicker.setMinValue(0);

     new AlertDialog.Builder(this)
        .setTitle("Quantity:")
        .setView(npView)
        .setPositiveButton("OK",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    //"OK" clicked
                }
            })
        .setNegativeButton("Cancel", null)
        .show();
Community
  • 1
  • 1
Nick
  • 3,504
  • 2
  • 39
  • 78