Monday, 27 May 2013

Android Calendar Sync | Android Custom Calendar | Android Calendar event!Android Custom Calendar View

    Hello Friends,

   Have you Searching for Android calender syncing in your android app.Displaying
   all the events, birthday, reminder and meeting In your android app. Today I am sharing my
   another android tutorial for android custom calendar view and listing all the calendar
   event in my own android app. It is a small sample application for syncing of android
   calender events.


android calender
android calender



Calander syncing
android calander syncing




 
 1. CalendarView.java


package com.examples.android.calendar;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.Locale;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class CalendarView extends Activity {

 public GregorianCalendar month, itemmonth;// calendar instances.

 public CalendarAdapter adapter;// adapter instance
 public Handler handler;// for grabbing some event values for showing the dot
       // marker.
 public ArrayList items; // container to store calendar items which
         // needs showing the event marker
 ArrayList event;
 LinearLayout rLayout;
 ArrayList date;
 ArrayList desc;

 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.calendar);
  Locale.setDefault(Locale.US);

  rLayout = (LinearLayout) findViewById(R.id.text);
  month = (GregorianCalendar) GregorianCalendar.getInstance();
  itemmonth = (GregorianCalendar) month.clone();

  items = new ArrayList();

  adapter = new CalendarAdapter(this, month);

  GridView gridview = (GridView) findViewById(R.id.gridview);
  gridview.setAdapter(adapter);

  handler = new Handler();
  handler.post(calendarUpdater);

  TextView title = (TextView) findViewById(R.id.title);
  title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));

  RelativeLayout previous = (RelativeLayout) findViewById(R.id.previous);

  previous.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    setPreviousMonth();
    refreshCalendar();
   }
  });

  RelativeLayout next = (RelativeLayout) findViewById(R.id.next);
  next.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    setNextMonth();
    refreshCalendar();

   }
  });

  gridview.setOnItemClickListener(new OnItemClickListener() {
   public void onItemClick(AdapterView parent, View v,
     int position, long id) {
    // removing the previous view if added
    if (((LinearLayout) rLayout).getChildCount() > 0) {
     ((LinearLayout) rLayout).removeAllViews();
    }
    desc = new ArrayList();
    date = new ArrayList();
    ((CalendarAdapter) parent.getAdapter()).setSelected(v);
    String selectedGridDate = CalendarAdapter.dayString
      .get(position);
    String[] separatedTime = selectedGridDate.split("-");
    String gridvalueString = separatedTime[2].replaceFirst("^0*",
      "");// taking last part of date. ie; 2 from 2012-12-02.
    int gridvalue = Integer.parseInt(gridvalueString);
    // navigate to next or previous month on clicking offdays.
    if ((gridvalue > 10) && (position < 8)) {
     setPreviousMonth();
     refreshCalendar();
    } else if ((gridvalue < 7) && (position > 28)) {
     setNextMonth();
     refreshCalendar();
    }
    ((CalendarAdapter) parent.getAdapter()).setSelected(v);

    for (int i = 0; i < Utility.startDates.size(); i++) {
     if (Utility.startDates.get(i).equals(selectedGridDate)) {
      desc.add(Utility.nameOfEvent.get(i));
     }
    }

    if (desc.size() > 0) {
     for (int i = 0; i < desc.size(); i++) {
      TextView rowTextView = new TextView(CalendarView.this);

      // set some properties of rowTextView or something
      rowTextView.setText("Event:" + desc.get(i));
      rowTextView.setTextColor(Color.BLACK);

      // add the textview to the linearlayout
      rLayout.addView(rowTextView);

     }

    }

    desc = null;

   }

  });
 }

 protected void setNextMonth() {
  if (month.get(GregorianCalendar.MONTH) == month
    .getActualMaximum(GregorianCalendar.MONTH)) {
   month.set((month.get(GregorianCalendar.YEAR) + 1),
     month.getActualMinimum(GregorianCalendar.MONTH), 1);
  } else {
   month.set(GregorianCalendar.MONTH,
     month.get(GregorianCalendar.MONTH) + 1);
  }

 }

 protected void setPreviousMonth() {
  if (month.get(GregorianCalendar.MONTH) == month
    .getActualMinimum(GregorianCalendar.MONTH)) {
   month.set((month.get(GregorianCalendar.YEAR) - 1),
     month.getActualMaximum(GregorianCalendar.MONTH), 1);
  } else {
   month.set(GregorianCalendar.MONTH,
     month.get(GregorianCalendar.MONTH) - 1);
  }

 }

 protected void showToast(String string) {
  Toast.makeText(this, string, Toast.LENGTH_SHORT).show();

 }

 public void refreshCalendar() {
  TextView title = (TextView) findViewById(R.id.title);

  adapter.refreshDays();
  adapter.notifyDataSetChanged();
  handler.post(calendarUpdater); // generate some calendar items

  title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));
 }

 public Runnable calendarUpdater = new Runnable() {

  @Override
  public void run() {
   items.clear();

   // Print dates of the current week
   DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
   String itemvalue;
   event = Utility.readCalendarEvent(CalendarView.this);
   Log.d("=====Event====", event.toString());
   Log.d("=====Date ARRAY====", Utility.startDates.toString());

   for (int i = 0; i < Utility.startDates.size(); i++) {
    itemvalue = df.format(itemmonth.getTime());
    itemmonth.add(GregorianCalendar.DATE, 1);
    items.add(Utility.startDates.get(i).toString());
   }
   adapter.setItems(items);
   adapter.notifyDataSetChanged();
  }
 };
}




2. CalendarAdapter.java
package com.examples.android.calendar;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CalendarAdapter extends BaseAdapter {
 private Context mContext;

 private java.util.Calendar month;
 public GregorianCalendar pmonth; // calendar instance for previous month
 /**
  * calendar instance for previous month for getting complete view
  */
 public GregorianCalendar pmonthmaxset;
 private GregorianCalendar selectedDate;
 int firstDay;
 int maxWeeknumber;
 int maxP;
 int calMaxP;
 int lastWeekDay;
 int leftDays;
 int mnthlength;
 String itemvalue, curentDateString;
 DateFormat df;

 private ArrayList items;
 public static List dayString;
 private View previousView;

 public CalendarAdapter(Context c, GregorianCalendar monthCalendar) {
  CalendarAdapter.dayString = new ArrayList();
  Locale.setDefault(Locale.US);
  month = monthCalendar;
  selectedDate = (GregorianCalendar) monthCalendar.clone();
  mContext = c;
  month.set(GregorianCalendar.DAY_OF_MONTH, 1);
  this.items = new ArrayList();
  df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
  curentDateString = df.format(selectedDate.getTime());
  refreshDays();
 }

 public void setItems(ArrayList items) {
  for (int i = 0; i != items.size(); i++) {
   if (items.get(i).length() == 1) {
    items.set(i, "0" + items.get(i));
   }
  }
  this.items = items;
 }

 public int getCount() {
  return dayString.size();
 }

 public Object getItem(int position) {
  return dayString.get(position);
 }

 public long getItemId(int position) {
  return 0;
 }

 // create a new view for each item referenced by the Adapter
 public View getView(int position, View convertView, ViewGroup parent) {
  View v = convertView;
  TextView dayView;
  if (convertView == null) { // if it's not recycled, initialize some
         // attributes
   LayoutInflater vi = (LayoutInflater) mContext
     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   v = vi.inflate(R.layout.calendar_item, null);

  }
  dayView = (TextView) v.findViewById(R.id.date);
  // separates daystring into parts.
  String[] separatedTime = dayString.get(position).split("-");
  // taking last part of date. ie; 2 from 2012-12-02
  String gridvalue = separatedTime[2].replaceFirst("^0*", "");
  // checking whether the day is in current month or not.
  if ((Integer.parseInt(gridvalue) > 1) && (position < firstDay)) {
   // setting offdays to white color.
   dayView.setTextColor(Color.WHITE);
   dayView.setClickable(false);
   dayView.setFocusable(false);
  } else if ((Integer.parseInt(gridvalue) < 7) && (position > 28)) {
   dayView.setTextColor(Color.WHITE);
   dayView.setClickable(false);
   dayView.setFocusable(false);
  } else {
   // setting curent month's days in blue color.
   dayView.setTextColor(Color.BLUE);
  }

  if (dayString.get(position).equals(curentDateString)) {
   setSelected(v);
   previousView = v;
  } else {
   v.setBackgroundResource(R.drawable.list_item_background);
  }
  dayView.setText(gridvalue);

  // create date string for comparison
  String date = dayString.get(position);

  if (date.length() == 1) {
   date = "0" + date;
  }
  String monthStr = "" + (month.get(GregorianCalendar.MONTH) + 1);
  if (monthStr.length() == 1) {
   monthStr = "0" + monthStr;
  }

  // show icon if date is not empty and it exists in the items array
  ImageView iw = (ImageView) v.findViewById(R.id.date_icon);
  if (date.length() > 0 && items != null && items.contains(date)) {
   iw.setVisibility(View.VISIBLE);
  } else {
   iw.setVisibility(View.INVISIBLE);
  }
  return v;
 }

 public View setSelected(View view) {
  if (previousView != null) {
   previousView.setBackgroundResource(R.drawable.list_item_background);
  }
  previousView = view;
  view.setBackgroundResource(R.drawable.calendar_cel_selectl);
  return view;
 }

 public void refreshDays() {
  // clear items
  items.clear();
  dayString.clear();
  Locale.setDefault(Locale.US);
  pmonth = (GregorianCalendar) month.clone();
  // month start day. ie; sun, mon, etc
  firstDay = month.get(GregorianCalendar.DAY_OF_WEEK);
  // finding number of weeks in current month.
  maxWeeknumber = month.getActualMaximum(GregorianCalendar.WEEK_OF_MONTH);
  // allocating maximum row number for the gridview.
  mnthlength = maxWeeknumber * 7;
  maxP = getMaxP(); // previous month maximum day 31,30....
  calMaxP = maxP - (firstDay - 1);// calendar offday starting 24,25 ...
  /**
   * Calendar instance for getting a complete gridview including the three
   * month's (previous,current,next) dates.
   */
  pmonthmaxset = (GregorianCalendar) pmonth.clone();
  /**
   * setting the start date as previous month's required date.
   */
  pmonthmaxset.set(GregorianCalendar.DAY_OF_MONTH, calMaxP + 1);

  /**
   * filling calendar gridview.
   */
  for (int n = 0; n < mnthlength; n++) {

   itemvalue = df.format(pmonthmaxset.getTime());
   pmonthmaxset.add(GregorianCalendar.DATE, 1);
   dayString.add(itemvalue);

  }
 }

 private int getMaxP() {
  int maxP;
  if (month.get(GregorianCalendar.MONTH) == month
    .getActualMinimum(GregorianCalendar.MONTH)) {
   pmonth.set((month.get(GregorianCalendar.YEAR) - 1),
     month.getActualMaximum(GregorianCalendar.MONTH), 1);
  } else {
   pmonth.set(GregorianCalendar.MONTH,
     month.get(GregorianCalendar.MONTH) - 1);
  }
  maxP = pmonth.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);

  return maxP;
 }

}


3. Utility.java


package com.examples.android.calendar;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;

public class Utility {
 public static ArrayList nameOfEvent = new ArrayList();
 public static ArrayList startDates = new ArrayList();
 public static ArrayList endDates = new ArrayList();
 public static ArrayList descriptions = new ArrayList();

 public static ArrayList readCalendarEvent(Context context) {
  Cursor cursor = context.getContentResolver()
    .query(Uri.parse("content://com.android.calendar/events"),
      new String[] { "calendar_id", "title", "description",
        "dtstart", "dtend", "eventLocation" }, null,
      null, null);
  cursor.moveToFirst();
  // fetching calendars name
  String CNames[] = new String[cursor.getCount()];

  // fetching calendars id
  nameOfEvent.clear();
  startDates.clear();
  endDates.clear();
  descriptions.clear();
  for (int i = 0; i < CNames.length; i++) {

   nameOfEvent.add(cursor.getString(1));
   startDates.add(getDate(Long.parseLong(cursor.getString(3))));
   endDates.add(getDate(Long.parseLong(cursor.getString(4))));
   descriptions.add(cursor.getString(2));
   CNames[i] = cursor.getString(1);
   cursor.moveToNext();

  }
  return nameOfEvent;
 }

 public static String getDate(long milliSeconds) {
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  Calendar calendar = Calendar.getInstance();
  calendar.setTimeInMillis(milliSeconds);
  return formatter.format(calendar.getTime());
 }
}



   Download the complete Source code 
   Calenderview.zip

   Enjoy coding :)

Mukesh Yadav

Hi Guys I am from Delhi working as Web/Mobile Application Developer(Android Developer), also have knowledge of Roboelctric and Mockito ,android test driven development... Blogging has been my passion and I think blogging is one of the powerful medium to share knowledge and ideas....

176 comments:

  1. Hello Mukesh,

    I have just implement same app like this for the event as a dot which display events. please share the code for this.

    THanks in Advance.

    ReplyDelete
  2. Hello Mukesh,
    I also need to implement app like this. please share the code for this as soon as possible.

    Thanks in Advance.

    ReplyDelete
  3. Hello Piyush

    I just doing some re factoring work in the code so I will provide the code soon, may be today evening with complete tutorial with the source code.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Hello Mukesh,

    In this calendar is the event which is display as dot is a static data???

    ReplyDelete
  6. Hello Mukesh,
    I have downloaded the code but in this the dot does't appear according to event.

    ReplyDelete
  7. Hello Piyush,
    In this calendar demo code I am using Static Array list for storing the event.But the good practice is to make a class Object for storing the data and then fetching the data from it.

    ReplyDelete
  8. Hello mukesh can you share youe email id please??

    ReplyDelete
  9. I am surprised , the same code I was using on my Htc phone and its fetching all my calendar events.


    my email id is : mukesh421985@gmail.com

    ReplyDelete
  10. Yes..But right now i am testing the app on emulator. And is it necessary to create a calendar account for that??

    ReplyDelete
  11. Okay, how it get the calender instance on emulator may be this is the one reason of getting
    unexpected result.

    In android phone there is a calender application. So try to run this sample on real android device instead of emulator. Also before running this please be sure that calendar application will be installed on your device, as in lower version of device (2.2,2.3) we have to download the calender app from google market.

    ReplyDelete
  12. OK..... But i have a little bit confusion when i have run this on real device then first no event display..but after enter in calendar app i have create a event so i can see event in this app as dot...so my que. is my data is coming from server so for add event everytime i have to go to calendar app???

    ReplyDelete
  13. Yes , If you device is sync with gmail account or you are login with gamil then its show all your google calendar event. Else you have to add manually.

    In your case as your data is coming from backend , you don't need to add it in the calendar app every time. Simply store all events in an object in key value pair(eg:1/1/2013=>new year). And in
    my above custom calender view code when I am populating or creating the calender view at that time I am checking if the calendar date is present in the object or not. if there is a date present in object , I just fetch the calender event corresponding to that date and bind it on the calendar.

    Check the logic where I am binding the event on that date from array object,and try the above approach which I said.I am sure its work charm for you.

    ReplyDelete
  14. i'm also copy paste this code but not getting run this app it force close at cursor event able columns not found.

    ReplyDelete
  15. Hello Prashant,
    I think your are execution this code in your android emulator.
    Try to run on android device then let me know if it is still crashing or not.
    I have test this code on HTC Explorer v-2.2.Its working fine.

    ReplyDelete
  16. HI mukesh i have downloaded u r program and i run in mobile but i am getting this error

    java.lang.SecurityException: Permission Denial: reading com.android.providers.calendar.CalendarProvider2 uri content://com.android.calendar/events from pid=2211, uid=10251 requires android.permission.READ_CALENDAR

    ReplyDelete
  17. Hello Soma,

    This is a permission issue,Please add Calendar permission in your AndroidManifest.xml file.
    android.permission.READ_CALENDAR

    ReplyDelete
  18. Hey thanks Mukesh its works me fine, can u guide me how to add Events in Calender, like Birthday , meeting and i want to keep alarm for that , It is possible??

    ReplyDelete
  19. Thanks and welcome..
    Yes, we can add alarm also.
    1. Regarding adding the event, its depends on you from where you are getting these event,(I mean by webservice). If you simply syncing the google calendar then simply open your google calendar add all meetings,event or birthday.These appliction will fetch all those events in the custom calendar.

    ReplyDelete
  20. Thanks for the reply ,

    I am not getting the event form webservice, i just want to add the event my manually. and i want to set the alarm for that . any idea

    ReplyDelete
  21. I need to list out all tthe events of the selected month in a page ?? how can i ??? pls help me

    ReplyDelete
  22. Hello,
    You have to make few change in above code...in my code I am comparing the current date with map of date event and binding all the event of current date.So before that you check the month and then even...few extra looping required in above code.
    Hopes now you got some idea.

    ReplyDelete
  23. Hi mukesh

    i wants to add the events in ur code, so tell me in which area i have to modify ur code. how to get the that dot . in calender view

    ReplyDelete
  24. check this method in CalendarView.java class....
    public Runnable calendarUpdater = new Runnable() {
    ---
    ---
    }

    Also Utility.startDates , here I am storing all events in an arraylist.

    ReplyDelete
  25. Hello Mekesh Yadav, i'm a student in Korea.
    i need ur code for my app for contest.
    So, can i use ur codes for my app?
    i will be appreciate for ur kindness
    Thank you

    ReplyDelete
  26. Three questions.

    How do you get the window popped-up when a user presses on a specific date for more information. And at the same time, the user closes the window when the user exits the window.

    How do you have a 'quote' displayed on the bottom of the calendar and having it played (like a scroll from right to left) for each of the dates

    On what database would you recommend to sync the calendar and the information on specific dates?

    Thank you.

    ReplyDelete
  27. Hello Mukesh,

    Thanks for nice post. I would like to add manually add event to your custom calendar not to device's built in calendar or else. Already I have tried to do this on the following portion:

    public Runnable calendarUpdater = new Runnable()
    {
    @Override
    public void run()
    {
    items.clear();

    // Print dates of the current week
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
    String itemvalue;
    event = Utility.readCalendarEvent(CalendarView.this);
    Log.d("=====Event====", event.toString());
    Log.d("=====Date ARRAY====", Utility.startDates.toString());

    for (int i = 0; i < Utility.startDates.size(); i++)
    {
    itemvalue = df.format(itemmonth.getTime());
    itemmonth.add(GregorianCalendar.DATE, 1);
    items.add(Utility.startDates.get(i).toString());
    }
    adapter.setItems(items);
    adapter.notifyDataSetChanged();
    }
    };

    but I am not able to do that. Can you please provide the code for this ? Then it will help me to learn this thing.

    ReplyDelete
  28. hey wen i am running your code on device its crashing giving following error trace

    08-01 12:06:36.180: E/AndroidRuntime(12883): java.lang.NumberFormatException: Invalid long: "null"
    08-01 12:06:36.180: E/AndroidRuntime(12883): at java.lang.Long.invalidLong(Long.java:125)
    08-01 12:06:36.180: E/AndroidRuntime(12883): at java.lang.Long.parseLong(Long.java:342)
    08-01 12:06:36.180: E/AndroidRuntime(12883): at java.lang.Long.parseLong(Long.java:319)
    08-01 12:06:36.180: E/AndroidRuntime(12883): at com.examples.android.calendar.Utility.readCalendarEvent(Utility.java:36)
    08-01 12:06:36.180: E/AndroidRuntime(12883): at com.examples.android.calendar.CalendarView$1.run(CalendarView.java:184)

    ReplyDelete
  29. Hello Mukesh i want to display calender inside the alert dialog exact like you so how to do this.

    Thanks,
    Android Developer.

    ReplyDelete
  30. Hi Mukesh,

    I need to add events for the particular date. can
    u share ur code for the events..

    ReplyDelete
  31. Hello Pavithra,

    You just need to change the array list of date according to your need in Utility class, and rest remain same.

    ReplyDelete
  32. Can u send ur code i just implement that and i ll change as per my requirements.. this is mail id pavithra.viji16@gmail.com..If u send that ll be very useful for me

    ReplyDelete
  33. hai Mukesh,,

    Can i please know about the license terms of this project???

    ReplyDelete
  34. can you please help me out with license terms of this project Mr.Mukesh???

    ReplyDelete
  35. Hello Rakesh,
    this is an open source code demo, there is no license or Policy. Feel free to use it.

    ReplyDelete
  36. Hello Pavithra,
    I have added the git repository of above code at the of the blog.You can also download it from there and Also I will just going to drop the code on your id .

    ReplyDelete
  37. I GOT THIS ERROR, WHEN I TRY TO RUN THE ZIP FILE.


    08-22 21:39:44.999: E/AndroidRuntime(1799): FATAL EXCEPTION: main
    08-22 21:39:44.999: E/AndroidRuntime(1799): java.lang.SecurityException: Permission Denial: opening provider com.android.providers.calendar.CalendarProvider2 from ProcessRecord{413e2d98 1799:com.examples.android.calendar/10085} (pid=1799, uid=10085) requires android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.os.Parcel.readException(Parcel.java:1327)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.os.Parcel.readException(Parcel.java:1281)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2201)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.app.ActivityThread.acquireProvider(ActivityThread.java:4024)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1629)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.content.ContentResolver.acquireProvider(ContentResolver.java:918)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.content.ContentResolver.query(ContentResolver.java:305)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at com.examples.android.calendar.Utility.readCalendarEvent(Utility.java:19)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at com.examples.android.calendar.CalendarView$1.run(CalendarView.java:184)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.os.Handler.handleCallback(Handler.java:605)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.os.Handler.dispatchMessage(Handler.java:92)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.os.Looper.loop(Looper.java:137)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at android.app.ActivityThread.main(ActivityThread.java:4424)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at java.lang.reflect.Method.invokeNative(Native Method)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at java.lang.reflect.Method.invoke(Method.java:511)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    08-22 21:39:44.999: E/AndroidRuntime(1799): at dalvik.system.NativeStart.main(Native Method)

    ReplyDelete
  38. Hello Dushyant,
    Please check the permission in android manifest file.
    android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR

    ReplyDelete
  39. Hi Mukesh,
    Your code is awesome,I am not able to download the code.Can u send your code i just implement that and made changes accordingly. this is mail id sudheer.412@gmail.com..If u send that will be very useful for me. Thanks in advance..

    ReplyDelete
  40. Did you take the zip file down? The gitHub download link appears to be unavailable.

    ReplyDelete
  41. Hello friend,I just updated the git repo linked.which was broken....sO please check now.

    Also , thanks for sending me email regarding the broken git repo link.

    ReplyDelete
  42. Great basic Calendar! It's a great starting point for me because it's easy to modify.

    ReplyDelete
  43. Is it possible to modify this code so that the calendar app synchs with a different Google account other than the one associated with the phone?

    ReplyDelete
  44. Yes, but for that first of all you have to login with that account via your code using google+ lib and then fetch all the events.

    ReplyDelete
  45. I need to add events for the particular date. can
    u share ur code for the events..

    ReplyDelete
  46. I'm trying to modify your code to gain read only access to a Google Calendar instead of my device's calendar. So in the Utility Class I'm trying to replace ".query(Uri.parse("content://com.android.calendar/events"),..." with "static String calendarURI = "https://www.google.com/calendar/feeds/[another gmail account]@gmail.com/private/full";...
    ...
    .query(Uri.parse(calendarURI), ..." I think I also need to append a password for authentication. Can you please show me how I can do this?

    ReplyDelete
    Replies
    1. have you figured this out yet? I am currently working on the exact same problem and am having issues with it.

      Delete
  47. hello...i downloaded the zip..but it is showing null pointer exception...could you please help me..

    ReplyDelete
    Replies
    1. i got the same error.....did u find any solution

      Delete
  48. Hi,
    This calendar starting Sunday.
    What should we do to begin Monday.
    Thanks.

    ReplyDelete
  49. Hi, I am a relatively new android programmer. I am trying to pull data from a database and incorporate it into the calendar. I am storing the event and time in two different columns. What would be the best way for me to do so?

    ReplyDelete
  50. Hi,

    I am a relatively new programmer and am designing an appointment app. I would like to change the events from a database. I currently have the event and the date stored in my database. How would I change the code to make it change from the Uri to a database? Would I only change the Utility.java or what else would I need to change? I would greatly appreciate your help.

    ReplyDelete
  51. Thanks for this post, but i want show event from server using web service then, where i will change in utility class. Help me for this

    ReplyDelete
  52. Yes.... you have to parse the event and then add that in object or arraylist.

    ReplyDelete
  53. Hi,
    This calendar starting Sunday.
    What should we do to begin Monday.
    Thanks.

    ReplyDelete
  54. Hi,
    This calendar starting Sunday.
    What should we do to begin Monday.
    Thanks.

    ReplyDelete
  55. hey any body tell me the code
    how we get selected date in 20 Jan 2013 format....plz reply soon

    ReplyDelete
  56. Hi,

    I've got a problem with your example.
    When i run it on my emulator it works fine, but on my real german android device (xperia arc s) it appears an error (... has unfortunately stoped).
    i think it's because i have a German device with a German calender, but i don't know.

    I hope you can help me

    ReplyDelete
  57. Mukesh thanks a lot, such an amazing code, but now i need to show List just of calendar Grid to show current month events, how can i do this?

    ReplyDelete
  58. Hi I have downloaded the zip file.. but event in coming when i tried to run in emulator...

    ReplyDelete
  59. Hello daniel,
    Try to run this on device bcoz it fetching events from gmail calender or from your phone calender app.
    If there is Calender app on your emulator then first add some event on it.

    ReplyDelete
  60. Hello Mukesh,
    Thanks you so much , its very useful to the beginners. Now i want facebook friends birthday events sync with calendar. what can i do for that. please help me. thanks

    ReplyDelete
  61. Hello Mukesh,

    Thanks you so much. its very useful to beginners. Now i want to sync facebook friends birthday into calendar. how i can do, please give me suggestions. Thanks

    ReplyDelete
  62. Hello Rakhi,
    Use facebook sdk and first get all calendar event then add those event on the calendar app.

    ReplyDelete
  63. Hello Mukesh,

    Can you please give me detailed explanation on how to sync with facebook for friends b'day.

    ReplyDelete
  64. Hi Mukesh,

    Its great. Can u update the code. When I select one day in previous or next month on the calendar then it display the next month calender, It doesn't highlighted the selected day.

    Thanks

    ReplyDelete
  65. Hello Mukesh. Thanks for great tutorial. if you don't mind can you please send me the calendar provider class database. Its very urgent ..thanks in advance

    ReplyDelete
  66. Hello Sravani,
    calendar provider class is the in build class. Tell me what exactly you want to do.

    ReplyDelete
  67. As i downloaded your code which is helpful to me.Now i want to add events to calendar those are visible on particular date.so please give me suggestions

    ReplyDelete
  68. The above code is doing the same...check the Utility class there I am using for loop to get all calendar event before that u have to add this code.

    String eventUriStr = "content://com.android.calendar/events";
    ContentValues event = new ContentValues();
    // id, We need to choose from our mobile for primary its 1
    event.put("calendar_id", 1);
    event.put("title", title);
    event.put("description", addInfo);
    event.put("eventLocation", place);
    event.put("eventTimezone", "UTC/GMT +2:00");

    // For next 1hr
    long endDate = startDate + 1000 * 60 * 60;
    event.put("dtstart", startDate);
    event.put("dtend", endDate);
    //If it is bithday alarm or such kind (which should remind me for whole day) 0 for false, 1 for true
    // values.put("allDay", 1);
    event.put("eventStatus", status);
    event.put("hasAlarm", 1);

    Uri eventUri = cr.insert(Uri.parse(eventUriStr), event);

    the above code add event into android calender. for more check this link
    http://stackoverflow.com/questions/16007549/android-add-event-to-calendar-using-intent-get-eventid

    ReplyDelete
  69. Hi Mukesh,
    This is lakshmi...Can u send ur code i just implement that and i ll change as per my requirements.. this is my mail id j.n.v.lakshmi@gmail.com..If u send that ll be very useful for me.please

    ReplyDelete
  70. Hello Lakshmi,
    download the complete from git repo
    https://github.com/mukesh4u/Android-Calendar-Sync

    ReplyDelete
  71. Hello Mukesh... when i try to run your code it will force close the apps..Pls help

    ReplyDelete
  72. Hello Isha....
    Are u running this on emulator....if yes then try to run on real device and then check

    ReplyDelete
  73. Hi Mukesh,

    The Calendar is Working great,I need to display only the current week in the gridview.I am hard to find out the problem.Please help me to solve the problem.

    ReplyDelete
  74. hi mukesh, am beginner for the android developer so pls give me a full tutorial like layout , string files also mukesh...

    ReplyDelete
  75. Hi, in a little number of device the application crash
    java.lang.NumberFormatException: Invalid long: "null"
    at java.lang.Long.invalidLong(Long.java:124)
    at java.lang.Long.parseLong(Long.java:341)
    at java.lang.Long.parseLong(Long.java:318)
    at com.MYPACAGE.Utility.readCalendarEvent(Utility.java:36)
    at com.MYPACAGE.CalendarView$1.run(CalendarView.java:198)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)

    I think when there are more the two calendar accounts.
    Can You help me?

    ReplyDelete
  76. Hello Mukesh your code not run in my tablet 4.2 it gave me error like
    01-24 15:14:37.497: E/AndroidRuntime(11075): java.lang.NumberFormatException: Invalid long: "null"
    01-24 15:14:37.497: E/AndroidRuntime(11075): at java.lang.Long.invalidLong(Long.java:125)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at java.lang.Long.parseLong(Long.java:342)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at java.lang.Long.parseLong(Long.java:319)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at com.examples.android.calendar.Utility.readCalendarEvent(Utility.java:36)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at com.examples.android.calendar.CalendarView$1.run(CalendarView.java:184)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at android.os.Handler.handleCallback(Handler.java:615)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at android.os.Handler.dispatchMessage(Handler.java:92)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at android.os.Looper.loop(Looper.java:137)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at android.app.ActivityThread.main(ActivityThread.java:4895)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at java.lang.reflect.Method.invokeNative(Native Method)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at java.lang.reflect.Method.invoke(Method.java:511)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
    01-24 15:14:37.497: E/AndroidRuntime(11075): at dalvik.system.NativeStart.main(Native Method)

    At Line endDates.add(getDate(Long.parseLong(cursor.getString(4))));
    how can i solve it?

    ReplyDelete
  77. Hi Mukesh,
    Great tutorial.
    I've been getting an error with endDate. Any idea why this is happening?

    01-24 22:58:20.823: E/AndroidRuntime(12538): java.lang.NumberFormatException: Invalid long: "null"
    01-24 22:58:20.823: E/AndroidRuntime(12538): at java.lang.Long.invalidLong(Long.java:125)
    01-24 22:58:20.823: E/AndroidRuntime(12538): at java.lang.Long.parseLong(Long.java:342)
    01-24 22:58:20.823: E/AndroidRuntime(12538): at java.lang.Long.parseLong(Long.java:319)
    01-24 22:58:20.823: E/AndroidRuntime(12538): at com.examples.android.calendar.Utility.readCalendarEvent(Utility.java:36)
    01-24 22:58:20.823: E/AndroidRuntime(12538): at com.examples.android.calendar.CalendarView$1.run(CalendarView.java:184)

    ReplyDelete
  78. Hi Mukesh ji,
    Thank you so much for your great tutorial on Custom Calendar. It's amazing to see your post and your responsiveness... Hats off... :)

    ReplyDelete
  79. How to display a particular (specific date) in calendar.Is it POSSIBLE?

    ReplyDelete
  80. Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
    [2014-02-10 16:56:13 - CalendarView] Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
    this will appear when i strat the application

    ReplyDelete
  81. please send me the code rahulostwal@gmail.com

    ReplyDelete
  82. Hi Mukesh in your source code if i set event for current year its not visible in next or previous years of calendar.
    Please reply as soon as possible its urgent need to implement its my project.

    ReplyDelete
  83. Hi Mukesh,
    Could you please send me the code at rahulostwal@gmail.com

    ReplyDelete
  84. Hello Rahul,
    download the complete code from git repo
    https://github.com/mukesh4u/Android-Calendar-Sync

    ReplyDelete
  85. When i run this in emulator, it says unfortunately the calender view has stopped.Please tell me the solution.

    ReplyDelete
  86. This comment has been removed by the author.

    ReplyDelete
  87. Hi Mukesh Yadav

    I tried to run you're code in emulator and android phone, but the result is unfortunately stopped. I don't know what seem's to be the problem. Please help

    Thank you

    ReplyDelete
    Replies
    1. Hello Annie,
      Please cross check the calendar permission in
      manifest file and try to run this code in real
      android phone not on emulator. If still facing
      issue then please share me the logcat error
      show that I will help you Or If possible drop
      me your code...

      Delete
  88. Hello Mr. Mukesh ....
    How can we display YEAR wise Calendar Events

    ReplyDelete
  89. Hello Mukesh,
    I have a date stored in the SQLite database. How can I highlight that date in this calendar?

    ReplyDelete
  90. hi Mukesh and thanks for example . but I have got a problem .

    " ....source not found sdk\platform\android-8\android.jar...."
    I hope . you can help me . regards

    ReplyDelete
  91. thank you mukesh, and i have a question, how can i activate the swipe control to get the next month in the calendar?

    ReplyDelete
  92. Hi, Mukesh, Thanks for your nice code.
    I found a bug in it because I used many services to generate my events on google calendar and so..
    On my smartphone your app crash because found some events without end date.
    so.. I have changed piece of code that read events to printout events title and date of events that return null as end date. and also "correct" to go on and enter in your app.

    public static ArrayList readCalendarEvent(Context context) {
    Cursor cursor = context.getContentResolver().query(
    Uri.parse("content://com.android.calendar/events"),
    new String[]{"calendar_id", "title", "description", "dtstart", "dtend", "eventLocation"},
    null, null, null);
    assert cursor != null;
    cursor.moveToFirst();
    // fetching calendars name
    String CNames[] = new String[cursor.getCount()];

    // fetching calendars id
    nameOfEvent.clear();
    startDates.clear();
    endDates.clear();
    descriptions.clear();
    for (int i = 0; i < CNames.length; i++) {
    String et = cursor.getString(1);
    String ed = cursor.getString(2);
    String es = cursor.getString(3);
    String ee = cursor.getString(4);

    es = getDate(Long.parseLong(es));

    if (ee == null) {
    Log.d("==readCalendarEvent:EndDate=Null?", "T="+et+" D="+ed+" S="+es );
    ee = es;
    } else {
    ee = getDate(Long.parseLong(ee));
    }

    nameOfEvent.add(et);
    descriptions.add(ed);
    startDates.add(es);
    endDates.add(ed);
    CNames[i] = et;

    cursor.moveToNext();
    }
    return nameOfEvent;
    }


    I just start to develop on Android so now I don't have good skill to investigate on event Database but I'm very curious to know if in row elements of event there is some info about service that generate event and so the null end date.
    How can I get more info about an event?

    Thanks, -Fixus971

    ReplyDelete
  93. Hello Mr, Mukesh
    It is really Great job.
    My question to you Can it is possible???
    suppose I am creating one Database table and then Add some events in that table and when I open calendar in my mobile device so that events is automatically bind in calendar view..

    ReplyDelete
  94. I am getting null pointer exception in this project when I run it first time

    ReplyDelete
  95. How to change first day of the week to Monday instead of Sunday?

    ReplyDelete
    Replies
    1. Do you find any answer? I have the same problem... Thanks!

      Delete
  96. Hi Mr. Mukesh,

    ThankYou for this nice code. I have some some problem with this, this calendar still displays the events even if it is already deleted.

    Kindly help me with this please.

    ReplyDelete
  97. Se puede capturar el evento del click en una fecha?

    ReplyDelete
  98. HI Mukesh,
    Your custom calendar is really very awesome. But, I have a task where I should show the calendar starting from present week to next 30 days. Please help me out

    ReplyDelete
  99. Hello Goutham,
    Share some screen shot of the ui...

    ReplyDelete
  100. Hello Mr, Mukesh
    It is really Great job.
    My question to you Can it is possible???
    suppose I am creating one Database table and then Add some events in that table and when I open calendar in my mobile device so that events is automatically bind in calendar view.. have u sample code then please share

    ReplyDelete
    Replies
    1. Hello Mayank,
      I don't have any sample code code(via:Database)

      Delete
  101. Hi Mukesh,
    Why the app does not working in KitKat version (4.4)

    ReplyDelete
  102. Yes, It is possible to bind the event from database.You havr to make change in utility class.

    ReplyDelete
    Replies
    1. have you any sample ? then please share

      Delete
    2. please send me sample code
      i request you please

      Delete
    3. Hello Mayank,
      I don't have any sample code code(via:Database)

      Delete
  103. hey how should i add event in your code
    can u give exmple
    wer shd i add event name description and how to set date

    ReplyDelete
  104. Hello Mukesh, i've modified the code to fetch data from MySQL database and it is working good. The thing is that i need to set the color of the item according to the event. How can i achieve that? In which section of the code i can set the cell color according to the data coming from Utility class? Thanks in Advance

    ReplyDelete
    Replies
    1. Hello Douglas, i need sample code please share your sample code.

      Delete
    2. i want your souce code please send me

      Delete
  105. Hello Douglas, check the adapter class. You need add few line in it which check your event and based on that event you can apply different cell color.

    ReplyDelete
    Replies
    1. hey mukesh, need help please
      i want to bind the event from database (sqlite)

      Delete
    2. Thanks a lot for your reply, the thing is that i'm blocked, i can't figure it out. Pleas help me, =D

      Delete
    3. I can change the color of the selected item according of the event but only when is selected, i need to do so on every item when the data is loaded from utility class. I really appreciate the help you can bring me.

      Delete
    4. Hello Mukesh, thanks for answering and sorry for delay, i have almost a week trying to get it to work and i can't can you give me a hint on this? I would really appreciate it. Thanks!

      Delete
  106. Hello Mukesh, I really like how your calendar example works. I'm trying to modify it so that it pulls events from my own mySQL database. Can you show me how to modify the code of your Utility class so that the data from a MySQL database can be displayed rather than the on-device calendar database? In my database, I've created the same fields you have: "calendar_id", "title", "description", "dtstart", "dtend","eventLocation". In my AsyncTask, should I bundle this data as HashMap, or ArrayLists or String Arrays? And can you show how to re-write the Utility Class to use this data? Thank you!

    ReplyDelete
  107. Hello Mukesh, could you please show me how to re-write the Utility Class using my own ArrayLists (calIdArrayList, calTitleArrayList, calDescrArrayList, calDayStartArrayList, calDayEndArrayList, calLocationArrayList) rather that calling the on-Device calendar database?

    ReplyDelete
  108. Hi Mukesh,

    I am creating a simple app to retrieve the events from the calendar. Can you please tell me how to do it? Can it be done using just the Intents?
    Thanks a lot.

    ReplyDelete
  109. Thank you :) i found nice calendar code. But, it doesn't work. Error:
    ...
    com.examples.android.calendar.Utility.readCalendarEvent(Utility.java:54)
    ...

    ReplyDelete
    Replies
    1. This code works only on Android versions below 4.0. What i did was to rewrite the utility class to load data from MySQL and the error is gone.

      Delete
  110. Hi Mukesh,
    Recurring events are not shown. That means birthday does not shown year to year. 4th june ,2013 birthday event only shown to that day. I cannot see it on next year. Whereas it shown normally on device calender. Can you please fix this issue?

    ReplyDelete
  111. It is a really good Job, but I need to change first day of the week to Monday instead of Sunday, any idea? Thanks!

    ReplyDelete
  112. Hi Mukesh. Can you send me code on how to only display all the events that we set. the app also should not allow the the user to create event. Help me...

    ReplyDelete
  113. hi mukesh,
    how can i add events in this calendar and i want to change these date's backgroud color, please give me answer as soon as possible

    ReplyDelete
  114. can you please m me some ideaz How to develop a hindu Calendar??

    ReplyDelete
  115. hi mukesh
    how to add events coming from webservice to your custom calendar??
    any idea? then plz share......

    ReplyDelete
    Replies
    1. Hello Jitu,
      Check the Utility class there I am binding all the events so modify the code inside Utility class - See more at: http://www.androiddevelopersolutions.com/2013/05/android-calendar-sync.html?showComment=1405837965050#c4887224162025092233

      Delete
  116. Hello Jitu,
    Check the Utility class there I am binding all the events so modify the code inside Utility class

    ReplyDelete
  117. Hello Mukesh,
    First of all thanks for a such great tutorial. Because of your tutorial now i don't need any library project.
    My question is this is month view of calendar. So is it possible to create week view using same code?
    If yes then please give me some idea.

    ReplyDelete
    Replies
    1. Thanks Sachin,
      Yes , week view is also possible. share me your view then I will give you the proper Idea .

      Delete
  118. Hello Mukesh,
    UI is similar to this project only current week will be displayed.
    http://i60.tinypic.com/mr946p.png
    Next button will display next week and previous will displayed previous week.

    ReplyDelete
  119. Hello Mukesh thanks a lot for this tutorial it's the best in help in LinkedIn I want to handle the reject of permission if the user click cancel to move me to the home Screen and to handle the accept to move me to another activity and thanks a lot

    ReplyDelete
  120. Hi Mukesh. I ran your program on android emulator version 4.1, it works perfectly, but when i try to run on my phone version 4.4 it crashed, have any idea, please help

    ReplyDelete
  121. can you help me how to sync my app with contacts like whats app

    ReplyDelete
  122. I'm trying to get this to run on 4.4 as well. What do we need to do to get it to work?

    ReplyDelete
  123. Really nice blog . it's save my much time

    ReplyDelete
  124. hi Mukesh

    i wand to add dynamic event and title (using web service return type is json date ,title ,event etc)
    on calender..
    plz help

    ReplyDelete
  125. Hi,
    I'm trying to get this to run on 4.4 but it didn't work.We use code in our project.Can you reload code?
    Regards.

    ReplyDelete
  126. Hi,
    I'm trying to get this to run on 4.4 but it didn't work.We use code in our project.Can you reload code?
    Regards.

    ReplyDelete
  127. How to get the calendar full Screen like to default CalendarView in API? Tried the match_parent etc. couldn't stretch to Full screen? Can you help me on this please?

    ReplyDelete
  128. Hi mukesh will you send me source code. my email id is jaypeemishraec@gmail.com. I want same functionality with dynamic data. please he me.

    ReplyDelete
    Replies
    1. Please check the link at the end , I already shared my code on git
      repository.

      Delete
  129. Nice mukesh it is work in fragment also

    ReplyDelete
  130. Hello Mukesh,
    First of all thanks for a such great tutorial.
    But i want to select multiple dates on Calendar View. I tried some way but it's not good. Can u help me, please??? (Tutorials, Links, etc)
    And my email: javiernguyen1412@gmail.com

    ReplyDelete
  131. Mr Mukesh I am having some problem i am using the custom calendar with sqlite database.That is for reading calendar event i am taking data from database and that database is populated by calling webservice http://www.credila.info/appinterface/credilaJson.php?task=getVisitRange&from=4-12-2015&to=09-12-2015&roi=R1234
    At first launch the databse is populated but the data is not shown on calendar.. on second launch it is showing data and count on calendar. I want to show this in first launch. Means the databse is populated and data is shown on calendar in first launch ... plz help me dear

    ReplyDelete
    Replies
    1. Hello,
      There is two way to do so, 1. when you are populating data
      from database at the same time insert those data into android
      default calender so that whenever you are showing your custom calendar view it fetch the event and bind it on the view,which I am doing in my Utility class.

      Another way : If you don't want to insert event in android
      default calendar then add all events in an arraylist and whenever
      you are calling your custom calendar view then compare
      calendar date from the arraylist.

      Delete
  132. hello buddy how would i automatically refresh calendar after adding record in database

    ReplyDelete
    Replies
    1. Hello,
      when you are adding data into database at the same time insert those data into android default calender which I am doing in my Utility class.

      Delete
  133. Hi,
    How to block dates before current date?

    ReplyDelete
  134. dear is this calendar working fine with 2016 year??? because right now this code is not able to call built in method of base adatper that is getItem and getView...
    please help me buddy

    ReplyDelete
    Replies
    1. Hello Deepti,
      Yes, Its working fine for Year-2016. In your case might be there is no event added in calendar for Year-2016. Please check.....you can also check it by adding some event manually.
      please let me know if still it doesn't worked.

      Delete
  135. Hello mukesh, Pleas send me a sample code for how can i add event in the calendar. I tried doing it but unable to achieve. Please send a sample code that will help me in showing the events in the calendar.

    ReplyDelete
  136. Hi mukesh, please help me out in adding events in the calendar code above. I have a list of dates and need an Dot on the calender date (indicating that date has a event). Please send me a sample code as i m finding difficult in achieving this.

    ReplyDelete
  137. hello,

    I am getting this error.

    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: FATAL EXCEPTION: main
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: Process: com.example.nidhi.hiral_calendar, PID: 24874
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: java.lang.NumberFormatException: Invalid long: "null"
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at java.lang.Long.invalidLong(Long.java:124)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at java.lang.Long.parseLong(Long.java:345)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at java.lang.Long.parseLong(Long.java:321)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at com.example.nidhi.hiral_calendar.Utility.readCalendarEvent(Utility.java:42)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at com.example.nidhi.hiral_calendar.CalendarView$4.run(CalendarView.java:187)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5294)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
    02-15 13:22:13.749 24874-24886/com.example.nidhi.hiral_calendar W/CursorWrapperInner: Cursor finalized without prior close()
    02-15 13:22:15.009 24874-24874/com.example.nidhi.hiral_calendar I/Process: Sending signal. PID: 24874 SIG: 9.


    plz help me out.
    Thanx

    ReplyDelete
    Replies
    1. Hello Nidhi..
      Add null check and check the format...as you are facing the ava.lang.NumberFormatException: Invalid long: "null"

      Delete
  138. hello

    i am getting this error in my locat.

    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: FATAL EXCEPTION: main
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: Process: com.example.nidhi.hiral_calendar, PID: 24874
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: java.lang.NumberFormatException: Invalid long: "null"
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at java.lang.Long.invalidLong(Long.java:124)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at java.lang.Long.parseLong(Long.java:345)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at java.lang.Long.parseLong(Long.java:321)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at com.example.nidhi.hiral_calendar.Utility.readCalendarEvent(Utility.java:42)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at com.example.nidhi.hiral_calendar.CalendarView$4.run(CalendarView.java:187)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5294)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
    02-15 13:22:08.120 24874-24874/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
    02-15 13:22:13.749 24874-24886/com.example.nidhi.hiral_calendar W/CursorWrapperInner: Cursor finalized without prior close()
    02-15 13:22:15.009 24874-24874/com.example.nidhi.hiral_calendar I/Process: Sending signal. PID: 24874 SIG: 9.

    plz help me out.
    Thank u.

    ReplyDelete
  139. Hi Mukesh,
    Really nice tutorial.Please tell me how do i allow the user to add his own events on a particular date and display the dot as you are doing. plz reply asap.

    ReplyDelete
  140. this codes perfectly works for me in terms of display, but i have encountered some problems in terms of its functionality. these includes:

    * the day and the date are not sync
    * the current day is still on April 2
    * when i press previous and next button, it will crashed
    * it wont display the saved events under the calendar

    please help me solve these problems, i need your answers badly :(

    you can contact me in my email address - makiutot@gmail.com in case you have an idea to solve my problem. thanks! :D

    ReplyDelete
  141. Hi man. Thank you for you tutorial. I just want to know how can we have a 7*6 calendar instead of 7*5?

    ReplyDelete
  142. Hi Man. Thank you for your great tutorial. I was wondering how can I have 6*7 calendar instead of 5*7? Thank you so much.

    ReplyDelete
  143. Hello Mukesh, do you have code to bind the event from database?

    ReplyDelete

 

Copyright @ 2013 Android Developer Blog.

Blog Widget by LinkWithin