我正在尝试使用rey5137's material library中的DatePickerDialog,但它无法实现方法OnDateSetListener。这是我的代码
dateFMCdialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
dateFMC.setText(dateFormatter.format(newDate.getTime()));
}
},newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
当我实现OnDateSetListener方法时,此代码给出了错误。看起来这个对话框不支持OnDateSetListener。我该怎么做才能从这个对话框中获取价值?谢谢。
答案 0 :(得分:1)
从https://github.com/rey5137/material/blob/master/lib/src/main/java/com/rey/material/widget/DatePicker.java#L430看起来该函数名为setOnDateChangedListener
,您需要实现OnDateChangedListener
:
/**
* Set the listener will be called when the selected date is changed.
* @param listener The {@link DatePicker.OnDateChangedListener} will be called.
*/
public void setOnDateChangedListener(OnDateChangedListener listener){
mOnDateChangedListener = listener;
}
/**
* Interface definition for a callback to be invoked when the selected date is changed.
*/
public interface OnDateChangedListener {
/**
* Called when the selected date is changed.
* @param oldDay The day value of old date.
* @param oldMonth The month value of old date.
* @param oldYear The year value of old date.
* @param newDay The day value of new date.
* @param newMonth The month value of new date.
* @param newYear The year value of new date.
*/
public void onDateChanged(int oldDay, int oldMonth, int oldYear, int newDay, int newMonth, int newYear);
}