문제

I'm trying to add a NumberPicker to an AlertDialog, but it does not apper even though there seems to be no error. I'm pretty newbie at Android coding so I assume it's something really stupid that's missing there.

        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();
도움이 되었습니까?

해결책

Add alert.setView(np); You have to tell alert dialog to set new view.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top