将事件添加到黑莓日历

时间:2011-12-01 06:46:29

标签: events blackberry calendar

我尝试将一个事件添加到黑莓日历中。使用以下代码:

EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST,PIM.WRITE_ONLY);
    _event = eventList.createEvent();

        String subject = _subject.getText().trim();
        String location = _location.getText().trim();
        long startTime = _startTime.getDate();
        long endTime = _endTime.getDate();
        String description = _desc.getText().trim();

        if (subject.length() == 0 || location.length() == 0)
        {
            Dialog.inform("Subject and location required");
            return false;
        }

        if ( endTime <= startTime || startTime < System.currentTimeMillis())
        {
            Dialog.inform("Invalid Start/End times");
            return false;
        }

        _event.addString(Event.SUMMARY, PIMItem.ATTR_NONE, subject );
        _event.addString(Event.LOCATION, PIMItem.ATTR_NONE, location);
        _event.addDate(Event.START, PIMItem.ATTR_NONE, startTime);
        _event.addDate(Event.END, PIMItem.ATTR_NONE, endTime);    
        _event.addString(Event.NOTE, PIMItem.ATTR_NONE, description);

        RepeatRule rule = new RepeatRule();


        switch(_recur.getSelectedIndex())
        {
            case 1:
                rule.setInt(RepeatRule.FREQUENCY,RepeatRule.DAILY);
                break;

            case 2:
                rule.setInt(RepeatRule.FREQUENCY,RepeatRule.WEEKLY);
                break;

            case 3:
                rule.setInt(RepeatRule.FREQUENCY,RepeatRule.MONTHLY);
                break;

            case 4:
                rule.setInt(RepeatRule.FREQUENCY,RepeatRule.YEARLY);
                break;        
        }


        _event.setRepeat(rule);


        _event.commit();

此代码取自Blackberry示例应用程序PIMDEMO

错误是:

  

事件在结束日期之后添加到日期

实施例: 如果我从2011年12月1日(开始日期)到2011年12月5日(结束日期)设置了一个事件,那么日历从12月1日到其后的所有日期(即事件永远不会结束)。

我在模拟器和黑莓珍珠9105中测试了这段代码。

1 个答案:

答案 0 :(得分:1)

删除以下RepeatRule代码并尝试。

 RepeatRule rule = new RepeatRule();


    switch(_recur.getSelectedIndex())
    {
        case 1:
            rule.setInt(RepeatRule.FREQUENCY,RepeatRule.DAILY);
            break;

        case 2:
            rule.setInt(RepeatRule.FREQUENCY,RepeatRule.WEEKLY);
            break;

        case 3:
            rule.setInt(RepeatRule.FREQUENCY,RepeatRule.MONTHLY);
            break;

        case 4:
            rule.setInt(RepeatRule.FREQUENCY,RepeatRule.YEARLY);
            break;        
    }


    _event.setRepeat(rule);