当用户单击它时,我使用自定义 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
但它仍然显示。我怎样才能不显示?