如何在Android的CalenderView中获取选定日期? [英] How can I get selected date in CalenderView in Android?
本文介绍了如何在Android的CalenderView中获取选定日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Calendar date = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd");
curDate = sdf.format(date.getTime());
我已经在onCreate方法中完成了上面的代码.但是它只能返回当前日期.我想要的是在日历中选择日期.
I have done the above code inside onCreate method. But it can only return the current date. What I want is to have the date selected in the calender.
<CalendarView
android:id="@+id/calendarView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
请帮助我
推荐答案
我使用了CalendarView
而不是日历,它现在可以正常工作.
I used CalendarView
instead of Calender and it's working now.
calendarView.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month,
int dayOfMonth) {
curDate = String.valueOf(dayOfMonth);
}
});
这篇关于如何在Android的CalenderView中获取选定日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文