使用ExtendedCalendarView显示事件信息

时间:2014-10-01 13:52:37

标签: java android calendar

我正在尝试为我的应用中的节目事件和相关信息创建自定义日历。 但我不知道如何显示这些信息。这是日历的代码:

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ExtendedCalendarView calendar = (ExtendedCalendarView)findViewById(R.id.calendar);
    ContentValues values = new ContentValues();
    values.put(CalendarProvider.COLOR, Event.COLOR_BLUE);
    values.put(CalendarProvider.DESCRIPTION, "Some Description");
    values.put(CalendarProvider.LOCATION, "Some location");
    values.put(CalendarProvider.EVENT, "Event name");

    Calendar cal = Calendar.getInstance();
    TimeZone tz = TimeZone.getDefault();
    cal.set(startDayYear, startDayMonth, startDayDay, startTimeHour, startTimeMin);
    int StartDayJulian = Time.getJulianDay(cal.getTimeInMillis(), TimeUnit.MILLISECONDS.toSeconds(tz.getOffset(cal.getTimeInMillis())));
    values.put(CalendarProvider.START, cal.getTimeInMillis());
    values.put(CalendarProvider.START_DAY, StartDayJulian);

    cal.set(endDayYear, endDayMonth, endDayDay, endTimeHour, endTimeMin);
    int endDayJulian = Time.getJulianDay(cal.getTimeInMillis(), TimeUnit.MILLISECONDS.toSeconds(tz.getOffset(cal.getTimeInMillis())));

    values.put(CalendarProvider.END, cal.getTimeInMillis());
    values.put(CalendarProvider.END_DAY, endDayJulian);

   // Uri uri = getContentResolver().insert(CalendarProvider.CONTENT_URI, values);
}

我可以看到日历和事件,但可能我要实现一些“Onclick”方法来显示信息。任何使用此库的人都可以帮助我吗?因为我无法找到任何有关的信息。 谢谢。

2 个答案:

答案 0 :(得分:4)

我自己找到了答案。

cal.setOnDayClickListener(new OnDayClickListener() {
        @Override
        public void onDayClicked(AdapterView<?> adapter, View view,
                int position, long id, Day day) {

            dayIsClicked = true;
            clickedDay = day;
            getScheduleDetails(day);

            list.setAdapter(new ListaAdapter(context, R.layout.itemlist,
                            itemsList));

                }

            }

    });

private void getScheduleDetails(Day day) {

itemsList = new ArrayList();

for (Event e : day.getEvents())
{   
    itemsList.add(e);
}

}

答案 1 :(得分:2)

我在日历下方的列表视图中显示信息。

像这样。 enter image description here

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout_location_site_calendar);
        this.ctx = this;

        this.extendedCalendarView = (ExtendedCalendarView) findViewById(R.id.extendedCalendarView_addLocationSiteCalendar_CALENDAR);
        this.listViewCalendar = (ListView) findViewById(R.id.listView_addLocationSiteCalendar_CALENDARLIST);
        //Disable Scrolling
        this.listViewCalendar.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        this.extendedCalendarView.setGesture(ExtendedCalendarView.LEFT_RIGHT_GESTURE);
        addEvent();//test
        addEvent2();//test

        initExtras(savedInstanceState);
        initListener();
    }


private void initListener() {
        extendedCalendarView.setOnDayClickListener(new ExtendedCalendarView.OnDayClickListener() {
            @Override
            public void onDayClicked(AdapterView<?> adapter, View view, int position, long id, Day day) {
                ArrayList<HashMap<Integer, String>> eventList = new ArrayList<HashMap<Integer, String>>();
                for (Event e : day.getEvents()) {
                    HashMap<Integer, String> event = new HashMap<Integer, String>();
                    event.put(NumericValues.LISTROW_ID_IMG_T_ST_IDC_KEY_TITLE, e.getTitle());
                    event.put(NumericValues.LISTROW_ID_IMG_T_ST_IDC_KEY_SUBTITLE, e.getDescription());
                    event.put(NumericValues.LISTROW_ID_IMG_T_ST_IDC_KEY_INDICATOR, e.getStartDate("hh:mm") + " - " + e.getEndDate("hh:mm"));
                    eventList.add(event);
                }
                CalendarListViewAdapter listAdapter = new CalendarListViewAdapter(_this, eventList);
                listViewCalendar.setAdapter(listAdapter);
                ListViewUtil.setListViewHeightBasedOnChildren(listViewCalendar);
            }
        });
    }

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

       <com.tyczj.extendedcalendarview.ExtendedCalendarView
            android:id="@+id/extendedCalendarView_addLocationSiteCalendar_CALENDAR"
            android:layout_height="350dp"
            android:layout_width="match_parent" />
        <ListView
            android:id="@+id/listView_addLocationSiteCalendar_CALENDARLIST"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="@drawable/list_divider"
            android:dividerHeight="1px"
            android:listSelector="@drawable/contacts_list_selector" />
    </LinearLayout>
</ScrollView>