DatePickerDialog 无法在 MaterialLibrary 上实现 OnDateSetListener
DatePickerDialog cannot implement OnDateSetListener on MaterialLibrary
我正在尝试使用 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。我应该怎么做才能从此对话中获得价值?谢谢。
从 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);
}
我正在尝试使用 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。我应该怎么做才能从此对话中获得价值?谢谢。
从 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);
}