简体   繁体   English

如何在Android中显示日历视图?

[英]How to display calendar view in Android?

In my application I need to display calendar and some events on it, like on image below. 在我的应用程序中,我需要在其上显示日历和一些事件,如下图所示。 在此处输入图片说明

I've read this topic, but libs described there doesn't fit my needs. 我已经阅读了主题,但是在那里描述的库不符合我的需求。 I've also found this lib: Extended Calendar View , but it works only on devices with api level 14 or higher while I need to support api level 10. 我也找到了这个库: Extended Calendar View ,但它仅在api级别为14或更高的设备上有效,而我需要支持api级别10。
Maybe someone know some library for solving this problem? 也许有人知道一些图书馆来解决这个问题? Any help will be highly appreciated. 任何帮助将不胜感激。

i referred this link to create something like that link 我引用了此链接以创建类似该链接的内容

/**
             * 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;
                }

In the above code create Hashmap which contains date. 在上面的代码中,创建包含日期的Hashmap。 and replace if condition with this(Make changes according to ur needs) 并替换是否满足此条件(根据您的需要进行更改)

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));}}

Changing each grid cell 更改每个网格单元

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()));

            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM