小编Par*_*xis的帖子

NumberPicker未在AlertDialog中显示

我正在尝试将一个NumberPicker添加到AlertDialog中,但即使看起来没有错误也没有apper.我是Android编码的新手,所以我认为这是一个非常愚蠢的东西.

        AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);

        alert.setTitle("Select the value: ");

        NumberPicker np = new NumberPicker(MainActivity.this);
        String[] nums = new String[100];
        for(int i=0; i<nums.length; i++)
               nums[i] = Integer.toString(i);

        np.setMinValue(1);
        np.setMaxValue(nums.length-1);
        np.setWrapSelectorWheel(false);
        np.setDisplayedValues(nums);
        np.setValue(50);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
          // Do something with value!
          }
        });

        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            // Cancel.
          }
        });

        alert.show();
Run Code Online (Sandbox Code Playgroud)

user-interface android components android-alertdialog numberpicker

5
推荐指数
1
解决办法
3684
查看次数