当我更改日期时,OnDateSetListener()
不会被调用。连线setMinDate(day);
都不行。我想由于某种原因DatePickerDialog
没有注册OnDateSetListener()
。但无法弄清楚。我已将对话框和侦听器都声明为全局的。
private DatePickerDialog datePicker;
private DatePickerDialog.OnDateSetListener dateListener;
代码 :
// Create dialogs for datePicker
private void createDatePicker() {
Calendar calendar = Calendar.getInstance(Locale.getDefault());
int day = calendar.get(Calendar.DAY_OF_MONTH);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
datePicker = new DatePickerDialog(this, dateListener, year, month, day);
datePicker.getDatePicker().setMinDate(day);
dateListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Log.d(TAG, "Date changed.");
}
};
}
private void setEditTextListeres() {
myEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
Log.d(TAG, "EditText gained focus.");
datePicker.show();
}
}
});
}
知道为什么不调用侦听器吗?为什么 setMinDate() 不起作用?