android – DatePickerDialog.OnDateSetListener在三星设备上没有回调

出于某些奇怪的原因,当我单击Positive按钮作为DatePickerDialog的一部分时,作为DateSetListener的一部分的onDateSet方法不会仅在SAMSUNG DEVICES上调用.

这是我在做的事情:

DateSetListener _datePickerDialogCallback = new DateSetListener();

DatePickerDialog _datePickerDialog = new DatePickerDialog(context, _datePickerDialogCallback, year, month, days);
_datePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE, StringUtil.getString(R.string.command_ok), new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface arg0, int arg1) {
      _done = true;
    }

  });

_datePickerDialog.show();



private class DateSetListener implements DatePickerDialog.OnDateSetListener {

  public void onDateSet(DatePicker view, int year, int month, int day) {

    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, day, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE),
        calendar.get(Calendar.SECOND));

    if (_done) {
      _view.setText(formatDate(calendar.getTime()));
    }
  }
}

关于为什么会发生这种情况的任何建议都将受到赞赏.请.请注意,这仅适用于SAMSUNG DEVICES

解决方法:

从ICS及以上看起来,在定义datePickerDialog时无需定义回调.但是,onPositiveButtonClick和onNegativeButtonClick必须调用回调.
就像是 :

    _datePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Ok", new DialogInterface.OnClickListener() {

      public void onClick(DialogInterface arg0, int arg1) {
        _done = true;
        DatePicker datePicker = _datePickerDialog.getDatePicker();
        _datePickerDialogCallback.onDateSet(datePicker, datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
      }

    });
上一篇:javascript – jquery ui datepicker转到今天按钮


下一篇:javascript – jquery datepicker无法处理创建的元素