android开发里跳过的坑——TimePickerDialog onTimeSet不回调

在android6.0.1上测试发现TimePickerDialog的onTimeSet和DatePickerDialog的onDateSet不回调,查看SDK源码发现,TimePickerDialog源码中该回调的调用在下面方法中调用:

@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case BUTTON_POSITIVE:
// Note this skips input validation and just uses the last valid time and hour
// entry. This will only be invoked programmatically. User clicks on BUTTON_POSITIVE
// are handled in show().
if (mTimeSetListener != null) {
mTimeSetListener.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(),
mTimePicker.getCurrentMinute());
}
break;
case BUTTON_NEGATIVE:
cancel();
break;
}
而我在上层调用时,使用了dialog.setButton重新实现了按钮功能,导致了该问题的发生。在代码中去掉dialog.setButton的实现即可解决该问题。DatePcikerDialog同理。
上一篇:Use API to retrieve data from internet


下一篇:TMOUT