0

カスタム ListPreference を使用して、ユーザーがクリックしたときにカスタム ダイアログを表示します。次のようになります。

 public class DeadLinePicker extends ListPreference{
     static final int DATE_DIALOG_ID = 1;
     static final int TIME_DIALOG_ID = 0;
     Dialog dialog;
     DeadLinePicker instance;
     Context context ; 
     private int mDay;
     private int mHour;
     private int mMinute;
     private int mYear;
     private int mMonth;

     public DeadLinePicker(Context context) {
            super(context);
            this.context = context;

        }
    public DeadLinePicker(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);
        mHour = c.get(Calendar.HOUR);
        mMinute = c.get(Calendar.MINUTE);

    }

     private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hourOfDay, int minuteOfHour) {
          mHour = hourOfDay;
          mMinute = minuteOfHour;
          updateDisplay();

        }
      };

         DatePickerDialog.OnDateSetListener mDateSetListener =
                 new DatePickerDialog.OnDateSetListener() {
                 public void onDateSet(DatePicker view, int year, int monthOfYear,
                                 int dayOfMonth) {
                         mYear = year;
                         mMonth = monthOfYear;
                         mDay = dayOfMonth;
                         updateDisplay();
                 }

         };
        private CustomListPreferenceAdapter customListPreferenceAdapter;
        protected Dialog onCreateDialog(int id) {
                switch (id) {
                case DATE_DIALOG_ID:
                        return new DatePickerDialog(context,
                                mDateSetListener,
                                mYear, mMonth, mDay);

                case TIME_DIALOG_ID:
                    return new TimePickerDialog(context, mTimeSetListener, mHour, mMinute,
                        false);

                }
                return null;
        }
        protected void onPrepareDialog(int id, Dialog dialog) {
                switch (id) {
                case DATE_DIALOG_ID:
                        ((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);

                        break;}
                }
        public void updateDisplay() {
            Activity activity = (Activity)context;
            instance = new DeadLinePicker(context);
            String minutes = null;
            if (mMinute>9)
                minutes = Integer.toString(mMinute);
            else 
                minutes = "0"+Integer.toString(mMinute);
            instance.setSummary(
                    new StringBuilder()
                    // Month is 0 based so add 1
                    .append(mYear).append("-")
                    .append(mMonth + 1).append("-")
                    .append(mDay)
                    .append(" ").append(mHour).append(":").append(minutes)
                    );
            activity.showDialog(DATE_DIALOG_ID);

    }
    @Override
        protected void onPrepareDialogBuilder(Builder builder) {

            super.onPrepareDialogBuilder(builder);
            builder.setNegativeButton(null, null);
            builder.setTitle(null);
            builder.setView(null);
            builder.setAdapter(null, null);
            Dialog alert  = builder.create();
            alert.dismiss();
        }
}

を呼び出すと、カスタム ダイアログが正常に表示updateDisplay()されonPreferenceClickます。しかし、その後も標準ダイアログが表示されます。見せないようにしたい。ヌルを設定しましonPrepareDialogBuilderたが、まだ表示されています。見せないようにするにはどうすればいいですか?

4

1 に答える 1