gpt4 book ai didi

java - DatePickerDialog 无法在 MaterialLibrary 上实现 OnDateSetListener

转载 作者:行者123 更新时间:2023-12-01 11:15:13 25 4
gpt4 key购买 nike

我正在尝试使用 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。我应该怎么做才能从这个对话框中获得值(value)?谢谢。

最佳答案

来自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;
}

来自https://github.com/rey5137/material/blob/master/lib/src/main/java/com/rey/material/widget/DatePicker.java#L72是要实现的接口(interface):

/**
* 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);
}

关于java - DatePickerDialog 无法在 MaterialLibrary 上实现 OnDateSetListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31910939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com