Android日历议程查看事件重叠

时间:2017-07-14 07:46:42

标签: android date events calendar

https://github.com/Tibolte/AgendaCalendarView/issues/119

使用baseCalendar向事件列表添加任何事件时,它会抛出java null指针异常, 除了添加事件之后,它们都会在同一个日期显示,日期是最后一个对象的日期!

https://user-images.githubusercontent.com/29772646/28202935-2f535622-6895-11e7-9062-8a40b6d1752d.png

private void mockList(List eventList) {

    Calendar calendar = new GregorianCalendar();
    Calendar startTime1 = calendar.getInstance();
    Calendar endTime1 = calendar.getInstance();
    int day,month,year,hour,minute;
    Date date = new Date();


    DateFormat sdf=new SimpleDateFormat("MM/dd/yyyy HH:mm:ss aa");
    // SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss aa"); 
    //6/5/2017 12:00:00 AM

    try {
        date =(Date) sdf.parse("7/14/2017 10:00:00 AM");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    day=date.getDate();
    month=date.getMonth();
    year=date.getYear();
    hour=date.getHours();
    minute=date.getMinutes(); 
    // startTime1.set(Calendar.YEAR,year);
    startTime1.set(Calendar.MONTH,month);
    startTime1.set(Calendar.DAY_OF_MONTH, day); 
    startTime1.set(Calendar.HOUR_OF_DAY, hour);
    startTime1.set(Calendar.MINUTE, minute);
    endTime1 = startTime1;

    eventList.add(new BaseCalendarEvent("First Event: Date 14", "A wonderful 
    journey!", "LOL",
            ContextCompat.getColor(this, R.color.orange_dark), startTime1, 
    endTime1, true));

    try {
        date =(Date) sdf.parse("7/15/2017 5:00:00 AM");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    day=date.getDate();
    month=date.getMonth();
    year=date.getYear();
    hour=date.getHours();
    minute=date.getMinutes();
    // startTime1.set(Calendar.YEAR,year);
    startTime1.set(Calendar.MONTH,month);
    startTime1.set(Calendar.DAY_OF_MONTH, day);
    startTime1.set(Calendar.HOUR_OF_DAY, hour);
    startTime1.set(Calendar.MINUTE, minute);
    endTime1 = startTime1;

    /*
    BaseCalendarEvent event1 = new BaseCalendarEvent("Thibault travels in 
    Iceland", 
    "A wonderful journey!", "Iceland",
    ContextCompat.getColor(this, R.color.orange_dark), startTime1, endTime1, 
    false);
    eventList.add(event1);
    */

    eventList.add(new BaseCalendarEvent("SEcond Event: Date 15", "A wonderful 
    journey!", "LOL",
            ContextCompat.getColor(this, R.color.orange_dark), startTime1, 
    endTime1, true));


    Calendar startTime3 = Calendar.getInstance();
    Calendar endTime3 = Calendar.getInstance();
    startTime3.set(Calendar.DAY_OF_MONTH,16);
    startTime3.set(Calendar.HOUR_OF_DAY, 16);
    startTime3.set(Calendar.MINUTE, 0);
    endTime3.set(Calendar.HOUR_OF_DAY, 15);
    endTime3.set(Calendar.MINUTE, 0);
    DrawableCalendarEvent event3 = new DrawableCalendarEvent("Visit of Harpa", 
    "", "Dalvík",
            ContextCompat.getColor(this, R.color.blue_dark), startTime3, 
    endTime3, false, android.R.drawable.ic_dialog_info);
    eventList.add(event3);
}

1 个答案:

答案 0 :(得分:0)

添加事件时创建

的新实例
Calendar startTime1 = calendar.getInstance();
Calendar endTime1 = calendar.getInstance(); 

还会捕获异常,以便添加更多事件。