要移动到下一个或前一个月您可以使用此代码:
mButtonNext = (Button) findViewById(R.id.buttonNext);
mButtonNext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(mCalendarView.getDate());
cal.add(Calendar.MONTH, 1);
mCalendarView.setDate(cal.getTimeInMillis(), true, true);
}
});
mButtonPrevious = (Button) findViewById(R.id.buttonPrevious);
mButtonPrevious.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(mCalendarView.getDate());
cal.add(Calendar.MONTH, -1);
mCalendarView.setDate(cal.getTimeInMillis(), true, true);
}
});
如果你想在默认日历添加事件,你必须看到发布的链接@ adam2510。 下面是一个示例代码,你可以使用:
public void addEvent() {
ContentResolver cr = mContext.getContentResolver();
ContentValues eventValues = new ContentValues();
eventValues.put(Events.TITLE, "title");
eventValues.put(Events.EVENT_LOCATION, "location");
eventValues.put(Events.DTSTART, startTimeMilliseconds);
eventValues.put(Events.DTEND, endTimeMilliseconds);
eventValues.put(Events.CALENDAR_ID, "1");//Defaul calendar
eventValues.put(Events.EVENT_TIMEZONE, TimeZone.SHORT);
cr.insert(Events.CONTENT_URI, eventValues);
}
但CalendarView
不言与事件一起使用。在Android文档中,您可以阅读CalendarView
:
“此类是用于显示和选择日期的日历小部件”。
我找不到改变单元格属性的简单方法。
如果您想在自己的caledar中添加事件,最好实施自己的日历,以便更改所有视图的属性。有大量的日历实现的,你可以在google.com找到
http://stackoverflow.com/a/7892512/1037074 这是你需要什么 – adam2510
@ adam2510在4.0,我们直接拖放日历视图,然后如何添加事件。但是在给定的代码中没有关于这个的代码。 – Venkat
这可能有助于https://developer.android.com/guide/topics/providers/calendar-provider.html在更新活动部分取得乐趣 – adam2510