2012-08-03 19 views
1

我创建了NumberPicker,但它出现空,我不能点击文本字段以外的任何东西,这是“0”,当我做了键盘弹出。这是图片来澄清我的意思。在Android API中的Empty NumberPicker 11

图片: enter image description here

这里是我用它来创建对话框代码:

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

SettingsActivity是我创建并显示该对话框中的活动。

,这里是我的对话框的XML:

<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> 

所以任何想法,我究竟错在这里做什么?

+0

你展示里面的onCreate你的对话? – Erol 2012-08-03 21:43:22

+0

即时消息显示我的对话框内首选点击是在onCreate – 2012-08-04 12:32:02

回答

2

你应该设置的最大值和最小值为您NumberPicker,比如像这样:

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); 
0

NumberPickerHolo.Light风格。请参阅this问题。

创建AlertDialog这样的:

 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(); 
相关问题