当我调用显示对话框时,我的应用程序出现了这个问题,它以某种方式被调用了两次。这只发生在 android 4.1 及更高版本上。较低版本工作正常,所以我不认为这是任何代码问题。
你以前听说过\遇到过这个问题吗?
这里的代码:
Button edit = (Button) ad.findViewById(R.id.editBtn);
edit.setTypeface(roboto);
edit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setDate();
ad.dismiss();
}
});
ad.show();
ad.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
shiftsActivity.setPressed(true);
}
});
}
public void setDate() {
// Initialize and open the set date dialog
DatePickerDialog setDateDialog = new DatePickerDialog(Shifts.this,
datePickerListener, dateAndTime.get(Calendar.YEAR),
dateAndTime.get(Calendar.MONTH),
dateAndTime.get(Calendar.DAY_OF_MONTH));
setDateDialog.setTitle("Set Date");
setDateDialog.show();
}
public void setStartTime() {
TimePickerDialog setStartTimeDialog = new TimePickerDialog(Shifts.this,
startTimePicker, dateAndTime.get(Calendar.HOUR),
dateAndTime.get(Calendar.MINUTE), true);
setStartTimeDialog.setTitle("Started At:");
setStartTimeDialog.show();
}
public void setEndTime() {
TimePickerDialog setEndTimeDialog = new TimePickerDialog(Shifts.this,
setEndTime, dateAndTime.get(Calendar.HOUR),
dateAndTime.get(Calendar.MINUTE), true);
setEndTimeDialog.setTitle("Ended:");
setEndTimeDialog.show();
}
TimePickerDialog.OnTimeSetListener startTimePicker = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
startIntHours = hourOfDay;
startIntMinutes = minute;
editStartTime = String.format("%02d", hourOfDay) + ":"
+ String.format("%02d", minute);
setEndTime();
}
};
TimePickerDialog.OnTimeSetListener setEndTime = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
finishIntHours = hourOfDay;
finsihIntMinutes = minute;
if (finishIntHours < startIntHours) {
finishIntHours = finishIntHours + Utility.HOURS_TIME_UNIT;
}
if (finsihIntMinutes < startIntMinutes) {
finsihIntMinutes = finsihIntMinutes + Utility.MINUTES_TIME_UNIT;
}
totalHours = finishIntHours - startIntHours;
totalMinutes = finsihIntMinutes - startIntMinutes;
Log.i("TotalHours in time picker", "" + totalHours);
Log.i("Totalminute in time picker", "" + totalMinutes);
editEndTime = String.format("%02d", hourOfDay) + ":"
+ String.format("%02d", minute);
replace(Shifts.view, Shifts.position);
}
};