在我的应用程序中,我需要在上面显示日历和一些事件,如下图所示。
我已经阅读了这个主题,但是那里描述的库不符合我的需要。我还找到了这个库:扩展日历视图,但它仅适用于 api 级别 14 或更高级别的设备,而我需要支持 api 级别 10。
也许有人知道一些解决这个问题的库?任何帮助将不胜感激。
我引用了这个链接来创建类似那个链接的东西
/**
* NOTE: YOU NEED TO IMPLEMENT THIS PART Given the YEAR, MONTH, retrieve
* ALL entries from a SQLite database for that month. Iterate over the
* List of All entries, and get the dateCreated, which is converted into
* day.
*
* @param year
* @param month
* @return
*/
private HashMap findNumberOfEventsPerMonth(int year, int month)
{
HashMap map = new HashMap<String, Integer>();
// DateFormat dateFormatter2 = new DateFormat();
//
// String day = dateFormatter2.format("dd", dateCreated).toString();
//
// if (map.containsKey(day))
// {
// Integer val = (Integer) map.get(day) + 1;
// map.put(day, val);
// }
// else
// {
// map.put(day, 1);
// }
return map;
}
在上面的代码中创建包含日期的 Hashmap。并用此替换 if 条件(根据您的需要进行更改)
if ((mEventsPerMonthMap != null) && (!mEventsPerMonthMap.isEmpty())) {
Set<String> keys = mEventsPerMonthMap.keySet();
for (String key : keys) {
if (key.equals(theday + "/" + monthInNo+ "/" + theyear)
&& mEventsPerMonthMap.containsKey((String.format("%02d", Integer.parseInt(theday)))
+ "/"+ monthInNo+ "/" + theyear)) {
datewiseEventmap.put(theday + "/" + monthInNo+"/" + theyear,
(ArrayList<Appointment>)
mEventsPerMonthMap.get((String.format("%02d",Integer.parseInt(theday)))+ "/" + monthInNo+ "/" + theyear));}}
更改每个网格单元
if (datewiseEventmap != null && datewiseEventmap.size() > 0) {
mNumEvents = (ArrayList<Appointment>) datewiseEventmap
.get(theday + "/" + monthInNo+ "/" + theyear);
eventName.setText(sbf);
eventName.setBackgroundResource(R.drawable.appointment_name_bg);
//gridcell.setBackgroundResource(R.drawable.calender_details_description);
eventCount.setVisibility(View.VISIBLE);
//eventCount.setBackgroundResource(R.drawable.calender_details_description);
if (mNumEvents.size() > 1) {
eventCount.setVisibility(View.VISIBLE);
eventCount.setText("+ " + String.valueOf(mNumEvents.size()));
}