添加自定义事件caldroid?自定义、事件、caldroid

2023-09-07 01:57:05 作者:你是我抓不住的梦

我一直在寻找一个日历视图这将让我添加自定义事件和it.Currently自定义我的应用程序是针对采用Android姜饼所有Android用户及以上caldroid似乎是最好的选择。我不能使用ExtendedCalendarView,因为它所需的最小API为14。

不过,我已经无法添加自定义事件我caldroid片段似乎没有多大帮助的文档。有人可以帮我这个?

解决方案

首先,创建CaldroidSampleCustomAdapter和CaldroidSampleCustomFragment喜欢这里的例子:的 https://github.com/roomorama/Caldroid/tree/master/demo/src/com/candroidsample

1,创建一个事件类:

 公共类事件{    公众诠释类型;    公共弦乐味精;    公共事件(int型的,弦乐味精){this.type =类型; this.msg =味精; }    公众的getMsg字符串(){返回this.msg;}} 

在CaldroidSampleCustomAdapter:

保护的HashMap<日期时间,事件>事件=新的HashMap<日期时间,事件>();

在CaldroidSampleCustomFragment添加方法:

私人的HashMap getEvents(日期时间的startTime,日期时间结束时间){

 的HashMap<弦乐,CalType>事件=新的HashMap<弦乐,CalType>();///从开始时间算起获得数据库事件结束时间返回的事件; 

}

Android自定义View 自定义Spinner

在CaldroidSampleCustomFragment编辑refreshView方式:

公共无效refreshView(){

//如果年份和月份尚未初始化,refreshView不做

//什么

如果(月== -1 ||年== -1){

返回;

}refreshMonthTitleTextView();

//刷新的日期网格视图

有关(CaldroidGridAdapter适配器:datePagerAdapters){

//重置caldroid数据

adapter.setCaldroidData(getCaldroidData());

//重置额外的数据

adapter.setExtraData(extraData);

//添加事件。

((CaldroidSampleCustomAdapter)适配器).events =事件

//刷新视图

adapter.notifyDataSetChanged();

}

}

最后,在CaldroidSampleCustomAdapter的getView方法中添加:

事件事件= this.events.get(DATETIME);

tv1.setText(event.getMsg());

I had been searching for a Calendar view which would allow me to add custom events and Customize it.Currently my app is targeted for all android users using Android Gingerbread and above and caldroid seems to be the best choice. I can't use ExtendedCalendarView because the min API required for it is 14.

However I've not been able to add custom events to my caldroid fragment and the documentation doesnt seem to help much. Can somebody help me out with this?

解决方案

First, create CaldroidSampleCustomAdapter and CaldroidSampleCustomFragment like example here: https://github.com/roomorama/Caldroid/tree/master/demo/src/com/candroidsample

1.Create a Event class:

public class Event { 
    public int type; 
    public String msg; 
    public Event(int type,String msg) { this.type = type; this.msg = msg; } 
    public String getMsg(){ return this.msg;}
} 

In CaldroidSampleCustomAdapter :

protected HashMap < DateTime, Event > events = new HashMap< DateTime,Event >();

In CaldroidSampleCustomFragment add method:

private HashMap getEvents(DateTime startTime,DateTime endTime) {

HashMap<String,CalType> events = new HashMap<String,CalType>(); 

/// get event of databases from startTime to endTime 

return events; 

}

In CaldroidSampleCustomFragment edit refreshView method:

public void refreshView() {

// If month and year is not yet initialized, refreshView doesn't do

// anything

if (month == -1 || year == -1) {

return;

} refreshMonthTitleTextView();

// Refresh the date grid views

for (CaldroidGridAdapter adapter : datePagerAdapters) {

// Reset caldroid data

adapter.setCaldroidData(getCaldroidData());

// Reset extra data

adapter.setExtraData(extraData);

// add events

((CaldroidSampleCustomAdapter)adapter).events = events

// Refresh view

adapter.notifyDataSetChanged();

}

}

Final, in getView method of CaldroidSampleCustomAdapter add:

Event event = this.events.get(dateTime);

tv1.setText(event.getMsg());