有一个非常好的libray(https://github.com/Applandeo/Material-Calendar-View)用于自定义android calenderview。例如,要将事件添加到calenderview,有一个名为Eventday.java的类,该类将日历对象和可绘制对象作为参数进行初始化。我希望它也可以采用字符串值,这样我也可以存储事件的描述,因为如果无法添加有关事件(字符串数据类型)的详细信息,则将事件添加到日历中没有意义。有人可以解决我的问题吗?
List<EventDay> events = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
//we cannot details about the event(string data) while initializing the EventDay class
events.add(new EventDay(calendar, R.drawable.absentic));
答案 0 :(得分:2)
首先进行自定义课程
import com.applandeo.materialcalendarview.EventDay;
import java.util.Calendar;
public class MyEventDay extends EventDay implements Parcelable {
private String mNote;
public MyEventDay(Calendar day, int imageResource, String note) {
super(day, imageResource);
mNote = note;
}
public String getNote() {
return mNote;
}
private MyEventDay(Parcel in) {
super((Calendar) in.readSerializable(), in.readInt());
mNote = in.readString();
}
public static final Creator<MyEventDay> CREATOR = new Creator<MyEventDay>() {
@Override
public MyEventDay createFromParcel(Parcel in) {
return new MyEventDay(in);
}
@Override
public MyEventDay[] newArray(int size) {
return new MyEventDay[size];
}
};
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeSerializable(getCalendar());
parcel.writeInt(getImageResource());
parcel.writeString(mNote);
}
@Override
public int describeContents() {
return 0;
}
}
在日历中添加事件
mEventDays.add(new MyEventDay(calender, R.drawable.ic_note_sticky, "I am Event");
用于检索字符串
calendarView.setOnDayClickListener(new OnDayClickListener() {
@Override
public void onDayClick(EventDay eventDay) {
Log.e("Event",((MyEventDay) eventDay).getNote()+" <--");
}
});
它对我有用,我希望它对您也有帮助
答案 1 :(得分:0)
当用户单击任意日期时,我使用此方法显示小弹出提示。
Map<Date,String> eventNotes = new HashMap<>()
eventNotes
setOnDayClickListener
中,使用键eventNote
检索了eventDay.getCalendar().getTime()