【问题标题】:Empty NumberPicker in android API 11android API 11 中的空 NumberPicker
【发布时间】:2012-08-01 22:12:37
【问题描述】:

我创建了 NumberPicker,但它显示为空,我无法单击除文本字段之外的任何其他内容,“0”在哪里,当我这样做时,键盘会弹出。这是一张图片来说明我的意思。

图片:

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

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>

所以任何想法我在这里做错了什么?

【问题讨论】:

  • 您是否在 onCreate 中显示您的对话框?
  • 我在 onCreate 内的首选项点击中显示我的对话框

标签: android dialog


【解决方案1】:

您应该为 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);

【讨论】:

    【解决方案2】:

    您的NumberPicker 不是Holo.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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-14
      • 2013-05-11
      • 2014-01-24
      • 2016-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多