数字选取器不显示数字



我试图创建一个包含NumberPickerAlertDialog
但是,它只显示两个分隔符,而不显示文本。

看http://imageshack.com/a/img673/8149/aWHQfj.png

我正在使用:

android:minSdkVersion="11"
android:targetSdkVersion="19"

法典:

    private void showInputDialog() {
    Context context = getActivity();
    RelativeLayout linearLayout = new RelativeLayout(context);
    final NumberPicker numberPicker = new NumberPicker(context);
    numberPicker.setMaxValue(1);
    numberPicker.setMinValue(100);
    numberPicker.setWrapSelectorWheel(false);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50);
    RelativeLayout.LayoutParams numPicerParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    numPicerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    linearLayout.setLayoutParams(params);
    linearLayout.addView(numberPicker,numPicerParams);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    alertDialogBuilder.setTitle("Number of strokes");
    alertDialogBuilder.setView(linearLayout);
    alertDialogBuilder
            .setCancelable(false)
            .setPositiveButton("Ok",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            int score = numberPicker.getValue();
                            if (mRows != null) {
                                if (mClickedColIndex > 10) mClickedColIndex -= 1;
                                mClickedPlayer.setManualScore(mClickedColIndex, score);
                            } else {
                                if (mClickedRowIndex > 10) mClickedRowIndex -= 1;
                                mClickedPlayer.setManualScore(mClickedRowIndex, score);
                            }
                            mClickedText.setText(Integer.toString(score));
                            setupScorecard();
                        }
                    })
            .setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                            int id) {
                            dialog.cancel();
                        }
                    });
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

我已经对该主题进行了多次搜索,但尚未找到任何有效的解决方案。

还有我不能设置的奇怪之处:android:numberPickerStyle风格.xml。

有人对此有任何想法吗?

更改以下内容:

numberPicker.setMaxValue(1);
numberPicker.setMinValue(100);

有了这个:

numberPicker.setMaxValue(100);
numberPicker.setMinValue(1);

最小值不能高于最大值。

最新更新