如何将焦点设置在CalendarView的具体日期知道日期和QUOT; DD / MM / YYYY" [英] How to set focus on a specific date in CalendarView knowing date is "dd/mm/yyyy"
问题描述
我试图找出如何设置一个焦点上的活动创建过程中CalendarView特定日期,日期是已知的,储存在一个单独的字符串变量,可以说 theDate
并具有 DD / MM / YYYY
知道了这一点,我可以让日历专注于一个特定的日期?
I'm trying to figure out how to set a focus on a specific date in CalendarView during activity creation, The date is known and stored in a separate string variable, lets say theDate
and has format of dd/mm/yyyy
Knowing this, can I make calendar focus on a specific date?
假设日历视图是 mCalendarView
在这种情况下。
Assume calendar view is mCalendarView
in this case.
推荐答案
尝试在CalendarView此方法:
的http://developer.android.com/reference/android/widget/CalendarView.html#setDate(long)
Try this method in CalendarView: http://developer.android.com/reference/android/widget/CalendarView.html#setDate(long)
对于DD / MM / YYYY格式之间进行转换,以毫秒为单位的格式,我建议你存储的日期格式毫秒,只显示日期时转换为DD / MM / YYYY格式。如果必须使用dd / mm / yyyy格式,不过,我会尝试以下方法:
As for converting between the dd/mm/yyyy format to milliseconds format, I recommend that you store the date in millisecond format and only convert to the dd/mm/yyyy format when displaying the date. If you have to use the dd/mm/yyyy format, though, I would try the following:
String date = "22/3/2014";
String parts[] = date.split("/");
int day = Integer.parseInt(parts[0]);
int month = Integer.parseInt(parts[1]);
int year = Integer.parseInt(parts[2]);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
long milliTime = calendar.getTimeInMillis();
和现在做设置日历视图中选定日期
And now set the selected date in the calendar view by doing
mCalendarView.setDate (milliTime, true, true);
这篇关于如何将焦点设置在CalendarView的具体日期知道日期和QUOT; DD / MM / YYYY"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!