datePickerDialog 中的onDateChanged函数为什么没有被触发
1个回答
2014-12-19 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517193
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
有点眉目,和大家分享下,写一个DatePickerDialog子类,在子类中重写onDateChanged函数,当然,声明空间要使用子类声明,子类如下:
public
class datePickerSon extends DatePickerDialog {
public
datePickerSon(Context context,
OnDateSetListener callBack, int
year, int monthOfYear,
int dayOfMonth) {
super(context, callBack, year, monthOfYear, dayOfMonth);
}
@Override
public void onDateChanged(DatePicker view, int year, int month,
int day) {
super.onDateChanged(view, year, month, day);
if(!isDateAfter(view)){
Calendar mCalendar =
Calendar.getInstance();
view.init(mCalendar.get(Calendar.YEAR),
mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), this);
}
}
private boolean isDateAfter(DatePicker tempView)
{
Calendar mCalendar = Calendar.getInstance();
Calendar
tempCalendar = Calendar.getInstance();
tempCalendar.set(tempView.getYear(), tempView.getMonth(),
tempView.getDayOfMonth(), 0, 0, 0);
if(tempCalendar.after(mCalendar))
return true;
else
return false;
}
}
public
class datePickerSon extends DatePickerDialog {
public
datePickerSon(Context context,
OnDateSetListener callBack, int
year, int monthOfYear,
int dayOfMonth) {
super(context, callBack, year, monthOfYear, dayOfMonth);
}
@Override
public void onDateChanged(DatePicker view, int year, int month,
int day) {
super.onDateChanged(view, year, month, day);
if(!isDateAfter(view)){
Calendar mCalendar =
Calendar.getInstance();
view.init(mCalendar.get(Calendar.YEAR),
mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), this);
}
}
private boolean isDateAfter(DatePicker tempView)
{
Calendar mCalendar = Calendar.getInstance();
Calendar
tempCalendar = Calendar.getInstance();
tempCalendar.set(tempView.getYear(), tempView.getMonth(),
tempView.getDayOfMonth(), 0, 0, 0);
if(tempCalendar.after(mCalendar))
return true;
else
return false;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询