将事件添加到此日历 [英] Add events to this Calender

查看:225
本文介绍了将事件添加到此日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个程序。它有一个日历。当用户在事件显示日期之后按下。

然后,我希望应用程序在事件即将发生时向用户发送通知。

日历我'使用的是从本网站日历示例

  package com.examples; 

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class SimpleCalendarViewActivity extends Activity implements OnClickListener
{
private static final String tag =SimpleCalendarViewActivity;

私人ImageView calendarToJournalButton;
private Button selectedDayMonthYearButton;
private Button currentMonth;
私人ImageView prevMonth;
私人ImageView nextMonth;
private GridView calendarView;
私有GridCellAdapter适配器;
私人日历_calendar;
private int month,year;
private final DateFormat dateFormatter = new DateFormat();
private static final String dateTemplate =MMMM yyyy;

/ **首次创建活动时调用。 * /
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_calendar_view);

_calendar = Calendar.getInstance(Locale.getDefault());
month = _calendar.get(Calendar.MONTH)+ 1;
year = _calendar.get(Calendar.YEAR);
Log.d(tag,Calendar Instance:=+Month:+ month ++Year:+ year);

selectedDayMonthYearButton =(Button)this.findViewById(R.id.selectedDayMonthYear);
selectedDayMonthYearButton.setText(Selected:);

prevMonth =(ImageView)this.findViewById(R.id.prevMonth);
prevMonth.setOnClickListener(this);

currentMonth =(Button)this.findViewById(R.id.currentMonth);
currentMonth.setText(dateFormatter.format(dateTemplate,_calendar.getTime()));

nextMonth =(ImageView)this.findViewById(R.id.nextMonth);
nextMonth.setOnClickListener(this);

calendarView =(GridView)this.findViewById(R.id.calendar);

//初始化
adapter = new GridCellAdapter(getApplicationContext(),R.id.calendar_day_gridcell,month,year);
adapter.notifyDataSetChanged();
calendarView.setAdapter(adapter);
}

/ **
*
* @param month
* @param year
* /
private void setGridCellAdapterToDate (int month,int year)
{
adapter = new GridCellAdapter(getApplicationContext(),R.id.calendar_day_gridcell,month,year);
_calendar.set(year,month - 1,_calendar.get(Calendar.DAY_OF_MONTH));
currentMonth.setText(dateFormatter.format(dateTemplate,_calendar.getTime()));
adapter.notifyDataSetChanged();
calendarView.setAdapter(adapter);
}

@Override
public void onClick(View v)
{
if(v == prevMonth)
{
if(month< = 1)
{
month = 11;

}
else
{
month--;
}
Log.d(标签,设置GridCellAdapter中的上个月+月:+月+年:+年);
setGridCellAdapterToDate(month,year);
}
if(v == nextMonth)
{
if(month> 11)
{
month = 1;
年++;
}
else
{
month ++;
}
Log.d(标签,设置GridCellAdapter下个月+月:+月+年:+年);
setGridCellAdapterToDate(month,year);
}

}

@Override
public void onDestroy()
{
Log.d(tag,Destroying查看...);
super.onDestroy();
}

// //////////////////////////////// ////////////////////////////////////////////////// //
//内部类
public class GridCellAdapter extends BaseAdapter implements OnClickListener
{
private static final String tag =GridCellAdapter;
private final Context _context;

private final List< String>列表;
private static final int DAY_OFFSET = 1;
private final String [] weekdays = new String [] {Sun,Mon,Tue,Wed,Thu,Fri,Sat};
private final String [] months = {January,February,March,April,May,June,July,August,September , 十一月十二月};
private final int [] daysOfMonth = {31,28,31,30,31,30,31,31,30,31,30,31}
private final int月,年;
private int daysInMonth,prevMonthDays;
private int currentDayOfMonth;
private int currentWeekDay;
private Button gridcell;
private TextView num_events_per_day;
private final HashMap eventsPerMonthMap;
private final SimpleDateFormat dateFormatter = new SimpleDateFormat(dd-MMM-yyyy);

//当前月份的天数
public GridCellAdapter(Context context,int textViewResourceId,int month,int year)
{
super();
this._context = context;
this.list = new ArrayList< String>();
this.month = month;
this.year = year;

Log.d(tag,==>通过日期FOR Month:+ month ++年:+年);
日历calendar = Calendar.getInstance();
setCurrentDayOfMonth(calendar.get(Calendar.DAY_OF_MONTH));
setCurrentWeekDay(calendar.get(Calendar.DAY_OF_WEEK));
Log.d(tag,New Calendar:=+ calendar.getTime()。toString());
Log.d(tag,CurrentDayOfWeek:+ getCurrentWeekDay());
Log.d(tag,CurrentDayOfMonth:+ getCurrentDayOfMonth());

//打印月份
printMonth(month,year);

//查找事件数
eventsPerMonthMap = findNumberOfEventsPerMonth(年,月);
}
private String getMonthAsString(int i)
{
return months [i];
}

private String getWeekDayAsString(int i)
{
return weekdays [i];
}

private int getNumberOfDaysOfMonth(int i)
{
return daysOfMonth [i];
}

public String getItem(int position)
{
return list.get(position);
}

@Override
public int getCount()
{
return list.size();
}

/ **
*打印月
*
* @param mm
* @param yy
* /
private void printMonth(int mm,int yy)
{
Log.d(tag,==&print; printMonth:mm:+ mm ++yy:+日);
//以
//本月初开始留空的天数。
int trailingSpaces = 0;
int leadSpaces = 0;
int daysInPrevMonth = 0;
int prevMonth = 0;
int prevYear = 0;
int nextMonth = 0;
int nextYear = 0;

int currentMonth = mm - 1;
String currentMonthName = getMonthAsString(currentMonth);
daysInMonth = getNumberOfDaysOfMonth(currentMonth);

Log.d(tag,Current Month:++ currentMonthName +have+ daysInMonth +days。

//格里高利日历:MINUS 1,设置为FIRST OF MONTH
GregorianCalendar cal = new GregorianCalendar(yy,currentMonth,1);
Log.d(tag,Gregorian Calendar:=+ cal.getTime()。toString());

if(currentMonth == 11)
{
prevMonth = currentMonth - 1;
daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth);
nextMonth = 0;
prevYear = yy;
nextYear = yy + 1;
Log.d(tag,* - > PrevYear:+ prevYear +PrevMonth:+ prevMonth +NextMonth:+ nextMonth +NextYear:+ nextYear);
}
else if(currentMonth == 0)
{
prevMonth = 11;
prevYear = yy - 1;
nextYear = yy;
daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth);
nextMonth = 1;
Log.d(tag,** - > PrevYear:+ prevYear +PrevMonth:+ prevMonth +NextMonth:+ nextMonth +NextYear:+ nextYear);
}
else
{
prevMonth = currentMonth - 1;
nextMonth = currentMonth + 1;
nextYear = yy;
prevYear = yy;
daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth);
Log.d(tag,*** ---> PrevYear:+ prevYear +PrevMonth:+ prevMonth +NextMonth:+ nextMonth +NextYear:+ nextYear);
}

//计算在
//月的第一天之前离开的金额。
// getDay()为星期日返回0。
int currentWeekDay = cal.get(Calendar.DAY_OF_WEEK) - 1;
trailingSpaces = currentWeekDay;

Log.d(tag,Week Day:+ currentWeekDay +is+ getWeekDayAsString(currentWeekDay));
Log.d(标签,否。追加空格添加:+尾随空格);
Log.d(标签,上一个月的天数++InitvMonth);

if(cal.isLeapYear(cal.get(Calendar.YEAR))&& mm == 2)
{
++ daysInMonth;
}

//尾随月份
(int i = 0; i< trailingSpaces; i ++)
{
Log.d ,PREV MONTH:=+ prevMonth +=>+ getMonthAsString(prevMonth)++ String.valueOf((daysInPrevMonth - trailingSpaces + DAY_OFFSET)+ i)
list.add(String.valueOf((daysInPrevMonth - trailingSpaces + / * DAY_OFFSET)* / 1)+ i)+-GREY+ - + getMonthAsString(prevMonth)+ - + prevYear)
}

//当前月份
(int i = 1; i = =日期InMonth; i ++)
{
Log.d currentMonthName,String.valueOf(i)++ getMonthAsString(currentMonth)++ yy);
if(i == getCurrentDayOfMonth())
{
list.add(String.valueOf(i)+-BLUE+ - + getMonthAsString(currentMonth)+ - + yy);
}
else
{
list.add(String.valueOf(i)+-WHITE+ - + getMonthAsString(currentMonth)+ - + yy) ;
}
}

//领先月份
for(int i = 0; i< list.size()%7; i ++)
{
Log.d(tag,NEXT MONTH:=+ getMonthAsString(nextMonth));
list.add(String.valueOf(i + 1)+-GREY+ - + getMonthAsString(nextMonth)+ - + nextYear);
}
}

/ **
*注意:您需要执行此部分给定年份MONTH,从$ a
*中获取所有条目该月份的SQLite数据库。迭代
*所有条目列表,并获取dateCreated,将其转换为
* day。
*
* @param年
* @param month
* @return
* /
私人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))
// {
//整数val =(整数)map.get(day)+ 1;
// map.put(day,val);
//}
// else
// {
// map.put(day,1);
//}
返回地图;
}

@Override
public long getItemId(int position)
{
return position;
}

@Override
public View getView(int position,View convertView,ViewGroup parent)
{
查看row = convertView;
if(row == null)
{
LayoutInflater inflater =(LayoutInflater)_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.calendar_day_gridcell,parent,false);
}

//获取对网格单元格的引用
gridcell =(Button)row.findViewById(R.id.calendar_day_gridcell);
gridcell.setOnClickListener(this);

// ACCOUNT FOR SPACING

Log.d(tag,Current Day:+ getCurrentDayOfMonth());
String [] day_color = list.get(position).split( - );
String theday = day_color [0];
String themonth = day_color [2];
String theyear = day_color [3];
if((!eventsPerMonthMap.isEmpty())&&(eventsPerMonthMap!= null))
{
if(eventsPerMonthMap.containsKey(theday))
{
num_events_per_day =(TextView)row.findViewById(R.id.num_events_per_day);
整数numEvents =(整数)eventsPerMonthMap.get(theday);
num_events_per_day.setText(numEvents.toString());
}
}

//设置Day GridCell
gridcell.setText(theday);
gridcell.setTag(theday + - + themonth + - + themear);
Log.d(tag,Setting GridCell+ theday + - + themonth + - + themear);

if(day_color [1] .equals(GRAY))
{
gridcell.setTextColor(Color.LTGRAY);
}
if(day_color [1] .equals(WHITE))
{
gridcell.setTextColor(Color.WHITE);
}
if(day_color [1] .equals(BLUE))
{
gridcell.setTextColor(getResources()。getColor(R.color.static_text_color));
}
返回行;
}
@Override
public void onClick(View view)
{
String date_month_year =(String)view.getTag();
selectedDayMonthYearButton.setText(Selected:+ date_month_year);

try
{
日期parsedDate = dateFormatter.parse(date_month_year);
Log.d(tag,Parsed Date:+ parsedDate.toString());

}
catch(ParseException e)
{
e.printStackTrace();
}
}

public int getCurrentDayOfMonth()
{
return currentDayOfMonth;
}

private void setCurrentDayOfMonth(int currentDayOfMonth)
{
this.currentDayOfMonth = currentDayOfMonth;
}
public void setCurrentWeekDay(int currentWeekDay)
{
this.currentWeekDay = currentWeekDay;
}
public int getCurrentWeekDay()
{
return currentWeekDay;
}
}
}

任何人都可以帮我添加事件和如何向用户发送通知?

解决方案

我觉得你对Google日历和日历感到困惑已经创建。实际上没有Android的默认日历应用程序。用户可以从网上获取Google日历,他可以使用他的邮件ID配置该日历。如果你必须创建任何事件,你应该访问这个日历,以便这样做。
在开始处理之前,请检查是否安装了Google日历。如果你正在使用一个模拟器,我建议你去一个真正的设备。



请参考以下链接。这可能有帮助。



如何在Android中设置提醒


I am developing a program. It has a calender. When the user presses on the date the event shows up.
Then I want the application to send a notifcation to the user whenever an event is about to happen.
The calendar I'm working with is from this site calendar example

package com.examples;    

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class SimpleCalendarViewActivity extends Activity implements OnClickListener
    {
        private static final String tag = "SimpleCalendarViewActivity";

        private ImageView calendarToJournalButton;
    private Button selectedDayMonthYearButton;
    private Button currentMonth;
    private ImageView prevMonth;
    private ImageView nextMonth;
    private GridView calendarView;
    private GridCellAdapter adapter;
    private Calendar _calendar;
    private int month, year;
    private final DateFormat dateFormatter = new DateFormat();
    private static final String dateTemplate = "MMMM yyyy";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.simple_calendar_view);

            _calendar = Calendar.getInstance(Locale.getDefault());
            month = _calendar.get(Calendar.MONTH) + 1;
            year = _calendar.get(Calendar.YEAR);
            Log.d(tag, "Calendar Instance:= " + "Month: " + month + " " + "Year: " + year);

            selectedDayMonthYearButton = (Button) this.findViewById(R.id.selectedDayMonthYear);
            selectedDayMonthYearButton.setText("Selected: ");

            prevMonth = (ImageView) this.findViewById(R.id.prevMonth);
            prevMonth.setOnClickListener(this);

            currentMonth = (Button) this.findViewById(R.id.currentMonth);
            currentMonth.setText(dateFormatter.format(dateTemplate, _calendar.getTime()));

            nextMonth = (ImageView) this.findViewById(R.id.nextMonth);
            nextMonth.setOnClickListener(this);

            calendarView = (GridView) this.findViewById(R.id.calendar);

            // Initialised
            adapter = new GridCellAdapter(getApplicationContext(), R.id.calendar_day_gridcell, month, year);
            adapter.notifyDataSetChanged();
            calendarView.setAdapter(adapter);
        }

    /**
     * 
     * @param month
     * @param year
     */
    private void setGridCellAdapterToDate(int month, int year)
        {
            adapter = new GridCellAdapter(getApplicationContext(), R.id.calendar_day_gridcell, month, year);
            _calendar.set(year, month - 1, _calendar.get(Calendar.DAY_OF_MONTH));
            currentMonth.setText(dateFormatter.format(dateTemplate, _calendar.getTime()));
            adapter.notifyDataSetChanged();
            calendarView.setAdapter(adapter);
        }

    @Override
    public void onClick(View v)
        {
            if (v == prevMonth)
                {
                    if (month <= 1)
                        {
                            month = 11;
                            year--;
                        }
                    else
                        {
                            month--;
                        }
                    Log.d(tag, "Setting Prev Month in GridCellAdapter: " + "Month: " + month + " Year: " + year);
                    setGridCellAdapterToDate(month, year);
                }
            if (v == nextMonth)
                {
                    if (month > 11)
                        {
                            month = 1;
                            year++;
                        }
                    else
                        {
                            month++;
                        }
                    Log.d(tag, "Setting Next Month in GridCellAdapter: " + "Month: " + month + " Year: " + year);
                    setGridCellAdapterToDate(month, year);
                }

        }

    @Override
    public void onDestroy()
        {
            Log.d(tag, "Destroying View ...");
            super.onDestroy();
        }

    // ///////////////////////////////////////////////////////////////////////////////////////
    // Inner Class
    public class GridCellAdapter extends BaseAdapter implements OnClickListener
        {
            private static final String tag = "GridCellAdapter";
            private final Context _context;

            private final List<String> list;
            private static final int DAY_OFFSET = 1;
            private final String[] weekdays = new String[]{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
            private final String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
            private final int[] daysOfMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
            private final int month, year;
            private int daysInMonth, prevMonthDays;
            private int currentDayOfMonth;
            private int currentWeekDay;
            private Button gridcell;
            private TextView num_events_per_day;
            private final HashMap eventsPerMonthMap;
            private final SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MMM-yyyy");

            // Days in Current Month
            public GridCellAdapter(Context context, int textViewResourceId, int month, int year)
                {
                    super();
                    this._context = context;
                    this.list = new ArrayList<String>();
                    this.month = month;
                    this.year = year;

                    Log.d(tag, "==> Passed in Date FOR Month: " + month + " " + "Year: " + year);
                    Calendar calendar = Calendar.getInstance();
                    setCurrentDayOfMonth(calendar.get(Calendar.DAY_OF_MONTH));
                    setCurrentWeekDay(calendar.get(Calendar.DAY_OF_WEEK));
                    Log.d(tag, "New Calendar:= " + calendar.getTime().toString());
                    Log.d(tag, "CurrentDayOfWeek :" + getCurrentWeekDay());
                    Log.d(tag, "CurrentDayOfMonth :" + getCurrentDayOfMonth());

                    // Print Month
                    printMonth(month, year);

                    // Find Number of Events
                    eventsPerMonthMap = findNumberOfEventsPerMonth(year, month);
                }
            private String getMonthAsString(int i)
                {
                    return months[i];
                }

            private String getWeekDayAsString(int i)
                {
                    return weekdays[i];
                }

            private int getNumberOfDaysOfMonth(int i)
                {
                    return daysOfMonth[i];
                }

            public String getItem(int position)
                {
                    return list.get(position);
                }

            @Override
            public int getCount()
                {
                    return list.size();
                }

            /**
             * Prints Month
             * 
             * @param mm
             * @param yy
             */
            private void printMonth(int mm, int yy)
                {
                    Log.d(tag, "==> printMonth: mm: " + mm + " " + "yy: " + yy);
                    // The number of days to leave blank at
                    // the start of this month.
                    int trailingSpaces = 0;
                    int leadSpaces = 0;
                    int daysInPrevMonth = 0;
                    int prevMonth = 0;
                    int prevYear = 0;
                    int nextMonth = 0;
                    int nextYear = 0;

                    int currentMonth = mm - 1;
                    String currentMonthName = getMonthAsString(currentMonth);
                    daysInMonth = getNumberOfDaysOfMonth(currentMonth);

                    Log.d(tag, "Current Month: " + " " + currentMonthName + " having " + daysInMonth + " days.");

                    // Gregorian Calendar : MINUS 1, set to FIRST OF MONTH
                    GregorianCalendar cal = new GregorianCalendar(yy, currentMonth, 1);
                    Log.d(tag, "Gregorian Calendar:= " + cal.getTime().toString());

                    if (currentMonth == 11)
                        {
                            prevMonth = currentMonth - 1;
                            daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth);
                            nextMonth = 0;
                            prevYear = yy;
                            nextYear = yy + 1;
                            Log.d(tag, "*->PrevYear: " + prevYear + " PrevMonth:" + prevMonth + " NextMonth: " + nextMonth + " NextYear: " + nextYear);
                        }
                    else if (currentMonth == 0)
                        {
                            prevMonth = 11;
                            prevYear = yy - 1;
                            nextYear = yy;
                            daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth);
                            nextMonth = 1;
                            Log.d(tag, "**--> PrevYear: " + prevYear + " PrevMonth:" + prevMonth + " NextMonth: " + nextMonth + " NextYear: " + nextYear);
                        }
                    else
                        {
                            prevMonth = currentMonth - 1;
                            nextMonth = currentMonth + 1;
                            nextYear = yy;
                            prevYear = yy;
                            daysInPrevMonth = getNumberOfDaysOfMonth(prevMonth);
                            Log.d(tag, "***---> PrevYear: " + prevYear + " PrevMonth:" + prevMonth + " NextMonth: " + nextMonth + " NextYear: " + nextYear);
                        }

                    // Compute how much to leave before before the first day of the
                    // month.
                    // getDay() returns 0 for Sunday.
                    int currentWeekDay = cal.get(Calendar.DAY_OF_WEEK) - 1;
                    trailingSpaces = currentWeekDay;

                    Log.d(tag, "Week Day:" + currentWeekDay + " is " + getWeekDayAsString(currentWeekDay));
                    Log.d(tag, "No. Trailing space to Add: " + trailingSpaces);
                    Log.d(tag, "No. of Days in Previous Month: " + daysInPrevMonth);

                    if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == 2)
                        {
                            ++daysInMonth;
                        }

                    // Trailing Month days
                    for (int i = 0; i < trailingSpaces; i++)
                        {
                            Log.d(tag, "PREV MONTH:= " + prevMonth + " => " + getMonthAsString(prevMonth) + " " + String.valueOf((daysInPrevMonth - trailingSpaces + DAY_OFFSET) + i));
                            list.add(String.valueOf((daysInPrevMonth - trailingSpaces + /*DAY_OFFSET)*/ 1) + i) + "-GREY" + "-" + getMonthAsString(prevMonth) + "-" + prevYear);
                        }

                    // Current Month Days
                    for (int i = 1; i <= daysInMonth; i++)
                        {
                            Log.d(currentMonthName, String.valueOf(i) + " " + getMonthAsString(currentMonth) + " " + yy);
                            if (i == getCurrentDayOfMonth())
                                {
                                    list.add(String.valueOf(i) + "-BLUE" + "-" + getMonthAsString(currentMonth) + "-" + yy);
                                }
                            else
                                {
                                    list.add(String.valueOf(i) + "-WHITE" + "-" + getMonthAsString(currentMonth) + "-" + yy);
                                }
                        }

                    // Leading Month days
                    for (int i = 0; i < list.size() % 7; i++)
                        {
                            Log.d(tag, "NEXT MONTH:= " + getMonthAsString(nextMonth));
                            list.add(String.valueOf(i + 1) + "-GREY" + "-" + getMonthAsString(nextMonth) + "-" + nextYear);
                        }
                }

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

            @Override
            public long getItemId(int position)
                {
                    return position;
                }

            @Override
            public View getView(int position, View convertView, ViewGroup parent)
                {
                    View row = convertView;
                    if (row == null)
                        {
                            LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            row = inflater.inflate(R.layout.calendar_day_gridcell, parent, false);
                        }

                    // Get a reference to the Day gridcell
                    gridcell = (Button) row.findViewById(R.id.calendar_day_gridcell);
                    gridcell.setOnClickListener(this);

                    // ACCOUNT FOR SPACING

                    Log.d(tag, "Current Day: " + getCurrentDayOfMonth());
                    String[] day_color = list.get(position).split("-");
                    String theday = day_color[0];
                    String themonth = day_color[2];
                    String theyear = day_color[3];
                    if ((!eventsPerMonthMap.isEmpty()) && (eventsPerMonthMap != null))
                        {
                            if (eventsPerMonthMap.containsKey(theday))
                                {
                                    num_events_per_day = (TextView) row.findViewById(R.id.num_events_per_day);
                                    Integer numEvents = (Integer) eventsPerMonthMap.get(theday);
                                    num_events_per_day.setText(numEvents.toString());
                                }
                        }

                    // Set the Day GridCell
                    gridcell.setText(theday);
                    gridcell.setTag(theday + "-" + themonth + "-" + theyear);
                    Log.d(tag, "Setting GridCell " + theday + "-" + themonth + "-" + theyear);

                    if (day_color[1].equals("GREY"))
                        {
                            gridcell.setTextColor(Color.LTGRAY);
                        }
                    if (day_color[1].equals("WHITE"))
                        {
                            gridcell.setTextColor(Color.WHITE);
                        }
                    if (day_color[1].equals("BLUE"))
                        {
                            gridcell.setTextColor(getResources().getColor(R.color.static_text_color));
                        }
                    return row;
                }
            @Override
            public void onClick(View view)
                {
                    String date_month_year = (String) view.getTag();
                    selectedDayMonthYearButton.setText("Selected: " + date_month_year);

                    try
                        {
                            Date parsedDate = dateFormatter.parse(date_month_year);
                            Log.d(tag, "Parsed Date: " + parsedDate.toString());

                        }
                    catch (ParseException e)
                        {
                            e.printStackTrace();
                        }
                }

            public int getCurrentDayOfMonth()
                {
                    return currentDayOfMonth;
                }

            private void setCurrentDayOfMonth(int currentDayOfMonth)
                {
                    this.currentDayOfMonth = currentDayOfMonth;
                }
            public void setCurrentWeekDay(int currentWeekDay)
                {
                    this.currentWeekDay = currentWeekDay;
                }
            public int getCurrentWeekDay()
                {
                    return currentWeekDay;
                }
        }
}

Can anyone help me to add the event and how to send a notification to the user?

解决方案

I think you are confusing with Google Calendar and the Calendar what you have created. Actually there is no default calendar app for android. The user can get a google calendar from net and he can configure that Calendar with his mail ID. And if you have to create any events or so, you should access this calendar in order to do so. Before you start working on it, check whether you have a google calendar installed. If you are using an emulator I would suggest you to go for a real device.

And refer to the below link. This might help.

How to set a reminder in Android?

这篇关于将事件添加到此日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆