Android Simple Calendar
Alot of people have been annoyed with the lack of a simple native calendar on Android…and rightfully so! Having to sync personal calendar events with Google’s online calendar may not be everyone’s frenzy. Some personal calendar events …are just that ..personal…mmh!
I am aware of AnCal by Piotr Zagawa and the new Calendar contained in OpenIntents by Karl Ostmo. There are also the calendar widgets which decorate the phonetop. Clearly, these guys should be appreciated in terms of their effort in coming up with a native Android Calendar.
In this tutorial, I would like to provide a quick skeleton framework for creating your own native Android Calendar. Feel free to improve, customize and hack at mine!
Download: SimpleCalendarImp.zip
Features:
– Contains slots to show number of events per day
File: simple_calendar_view.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg"> <ImageView android:id="@+id/calendarToJournalButton" android:src="@drawable/add_entry_button_selector" android:gravity="left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingBottom="10dip"> </ImageView> <Button android:id="@+id/selectedDayMonthYear" android:textColor="#FFFFFF" android:layout_gravity="center" android:textAppearance="?android:attr/textAppearanceMedium" android:background="@drawable/calendar_top_header" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/prevMonth" android:src="@drawable/calendar_left_arrow_selector" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ImageView> <Button android:id="@+id/currentMonth" android:layout_weight="0.6" android:textColor="#FFFFFF" android:textAppearance="?android:attr/textAppearanceMedium" android:background="@drawable/calendar_bar" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <ImageView android:id="@+id/nextMonth" android:src="@drawable/calendar_right_arrow_selector" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ImageView> </LinearLayout> <LinearLayout android:layout_gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/calendarheader" android:src="@drawable/blue_bg_with_text" android:layout_gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content"> </ImageView> </LinearLayout> <GridView android:id="@+id/calendar" android:numColumns="7" android:layout_width="fill_parent" android:layout_height="wrap_content"> </GridView> </LinearLayout>
File: day_gridcell.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/calendar_button_selector"> <Button android:id="@+id/calendar_day_gridcell" android:layout_gravity="center" android:textColor="#FFFFFF" android:background="@drawable/calendar_button_selector" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> <TextView android:id="@+id/num_events_per_day" style="@style/calendar_event_style" android:layout_gravity="right" android:layout_width="10dip" android:layout_height="10dip"> </TextView> </RelativeLayout>
File: SimpleCalendarViewActivity.java
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 = 12; 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 == 1) { ++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) + 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; } } }
Need to upload code for updated version!
Im not able to download the .zip file,it says Forbidden by administrator rules
please help.
Thanks
all my code is here:
https://github.com/w2davids/Ghostdrive
Im very beginner to Android, what about the adding events code 🙂
SQLite code.
could you please post that code.
And how to sync the calendar with Google/Outlook calendar
Thanks
Great app…. Please upload code for updated version… Would love to try it out also..
Updated version at download link.
Note: I have included the assets to maintain the calendar look & feel.
However, the developer needs to implement following code to obtain Number of Events per Day:
(I used ActiveRecord-Android, for connecting to SQLite, email me for the code)
private HashMap findNumberOfEventsPerMonth(int year, int month)
{
HashMap map = new HashMap();
// 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;
}
can you send the code to add events using SQLite to me
sanaa.jarrah@yahoo.com
could you please send me the events with sqlite code thanks in advance
Could You please share code for associating events with calender @ amitku25@rediffmail.com
please sent me the code to implement SQlite
velansms@gmail.com
I saw a good tutorial for SQLite database usage. It is simple, i think this will help you
http://www.compiletimeerror.com/2013/01/android-sqlite-database-tutorial.html
hey man please can you give me the code to add events using SQLite?
please sent me the code to implement SQlite salvettimariano@hotmail.com
Can you please send me the code to add events to the SQLite db? Thanks!
please send me the code with sqlite. thank you very much.
claire.caceres@gmail.com
Can you send the code to add events using SQLite to me
sojoesph111@yahoo.com.hk
Can you please send the code to add events using SQLite to me
ss_lcy123@hotmail.com
thanks in advance.
Hi, can you please send me this code, it would be much appreciated.
Thank you
nageab_clart@hotmail.co.uk
can you send the code to add events using SQLite
great post ! please email me the code too , mario.a.maroun@gmail.com
Very nice , please can you send me the codes to implement events and for connecting to SQLite? Thanks
Great calendar…. It did help a lot…..
This looks like just what I need to get started on my 1st app for android. If I manage to create anything useful, I would like to release my app under some kind of Free Software License.
What license (if any) is this code released under?
Have’nt decided ..most likely LGLP’d or some other liberal licence will apply
Concerning licencing…most likley LGPL’d…or some other liberal licence.
I any case feel free to send me an email.
Hi,
Thanks for your application, but while I’m trying to run it, it says “Could not find SimpleCalendarImp.apk!” can you help me please ?
Thanks in advance.
Hi Sajdad,
The apk is the android packaged file that is run on the emulator/ device. How may I ask are you running the project file?
1. Start Eclipse IDE
2. Right click “Import …” OR from the menu File -> Import ….
3. Point to the downloaded and unzipped project
4. Load the project.
5. Check if there are any errors on loading and check the build path.
6. Create a new AVD if necessary ( will run on Android 1.5 to 2.3 versions)
7. Run the project!
Hope that helps!
If there are any probs that please send an email describing the prob.
-w
Hi,
I want to implement the code into my application to retreive the date, but I can’t call the intent.
Can someone help me plz…!
(android verison 2.2)
@Override
public void onClick(View v) {
Intent i = new Intent(v.getContext(), FullCalendar.class);
startActivityForResult(i, 0);
}
Hi Aikito,
From your code, I see that you are intercepting an onClick event and want to call/launch the intent to view the FullCalendar class.
So, something like this :
public class YourClassActivity extends Activity implements OnClickListener
{
private ImageButton myCalendarButton;
@Override
public void onCreate( Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
myCalendarButton= (ImageButton) this.findViewById( R.id.myCalendarButton); //From XML view layer
//Bind your ImageButton to the EventListener
myCalendarButton.setOnClickListener( this);
}
…….
@Override
public void onClick( View v)
{
Intent intent= new Intent( this, FullCalendar.class) ;
startActivity( intent );
}
}
Notes:
If you have a scenario, where you click a button and launch the FullCalendar in the next view, then the above is what I usually use.
1. Ensure that the button in the XML view layer is bounded to an OnClickListener in the Java code ie. the class Actvity implements the OnClickListener.
2. Now bind the myCalendarButton to the event listener using the
myCalendarButton.setOnClickListener( this);
3. Override the onClick handler method and launch your new Intent from the current activity YourClassActivity ie. “this”
v.getContext() …would refer the a UI component which should respond to the click event….it’s better to refer to the YourClassActivity or simple getApplicationContext().
-W
Hiiiii want Dynamic Events calender source code which store in sqlite..
Hi w2davids,
It doesn’t work!
My application call a intent X, in the X intent I have a TextView
When I click on the TextView it suppose to call the intend Calendar with result expectation [ startActivityForResult(intent, 0); ]
This is a sample of my code :
in xml :
in java :
public class X extends Activity {
…
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.time_edit);
setTitle(“Time Edit”);
dateDiag = (TextView) findViewById(R.id.DateEdit);
dateDiag.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), Calendar.class);
startActivityForResult(intent , 0);
}
});
}
Used it several times….works for sure!
It is better to post your code, and a debug trace statement for following the program execution.
-w
Hi w2Divids,
haha sorry for all the trouble, is all my bad.
At the beginning, I just forgot to add the new class in AndroidManifest!
No probs…from your problem description I was unclear if the activity loaded successfully and just did not appear…or for some other reason.
I sometimes forget to bind the events to button, so everything is working but its not listening..hahah
Hi,
I was looking for this for a long time! Thanks a lot ^^
However, I have a little problem with the display of the current day. The current day number is displayed in dark blue in every month grid (For example, every 13th of each month is in dark blue).
Actually, I just want to display as this in the current month.
How do you think I can this?
Hi again,
For those who are interested, I found how to do what I wanted.
In the GridCellAdapter constructor, replace :
” setCurrentDayOfMonth(calendar.get(Calendar.DAY_OF_MONTH)); ”
by
“if (month == calendar.get(Calendar.MONTH)+1){ setCurrentDayOfMonth(calendar.get(Calendar.DAY_OF_MONTH));
}”
That’s it!
Thanks again for this app. It’s helping me a lot!
Bye
Hey Bertrand …thank you!
-w
Hi thanks ,,, very much useful..
can u send me a code to add events to this calendar???
if so send it to me now….or send me link to download it
Thanks, very useful. Just needed to check that it was also the current month on the blue text for highlighting today’s date.
if (i == getCurrentDayOfMonth() && currentMonth == todaysMonth – 1)
Sorry, I am new to Android and I have 2 questions.
1. I don’t see the part where you write an event to SQLite. Where should I put it?
2. I see the part where you have to query for an event from SQLite but can you give a little example.
Thanks in advance.
Wanted to keep the example general, that’s why I left out the SQL code.
For the SQL code, I use ActiveRecord-Android you’ll find it on my blog.
-W
Can you please share the link where from I can download SQLite code or you can mail me the code at the below mentioned mail id
Can u please send me a code to add events to this calender(basically the SQLite part). if so it will be a great help for me. If u can’t post here, pls send it to my email address.(shanuli.sliit@gmail.com).
Thanks.
Hi david
your calendar working fine. But I want to view my events from google calendar. I wrote code to add event to google calendar its working fine.
Calendar cal = Calendar.getInstance();
Intent event = new Intent(Intent.ACTION_EDIT);
event.setType(“vnd.android.cursor.item/event”);
//event.putExtra(“allDay”, true);
//event.putExtra(“rrule”, “FREQ=YEARLY”);
event.putExtra(“endTime”, cal.getTimeInMillis()+60*60*1000);
event.putExtra(“title”, “”);
startActivity(event);
I want similar type of code to view my events from my calendar…
if its possible please send me asap…
thanks in adv:
Where do you put this code in at?
https://github.com/w2davids/Ghostdrive
similarly how to view day view, week view, month view and agenda view.
thanks in adv:::
Hi,Thx for this great calender,it really help me alots in my diploma project,currently we are doing a calender appointment scheduling apps,can i ask you what is the log.d?
Log.d is android’s logging facility…U can see all the log information if you insert Log.d() statements into your code.
Helps with debugging your code.
you are a god send angel. i was so messed up in working with ancal that i had lost hope. plus my fellow iphone developer had found the same library from the apple website..so i was defending Andriod’s honor. thank you again.
can you send me a copy of SimpleCalendarImp.zip?
I can not download it. My email is luodan860514@gmail.com
Thank you very much!
HI, This is really very nice post,
Thanks for this,
One more things, i want to every Sunday in Red Colour , and every 2nd and 4th Saturdays in Red Colour how it is possible
Plz Help Me
Hitesh 9998576657
Hi this is very helpfull..
but i can download android project from fileFactory.
can you send me the project romanzah.basit@gmail.com .
thnkz…
Hi,
I can not download “SimpleCalendarImp.zip” files.
Can you send me the project to my mail address.
Thanks.
Hi,
I want to display the button in the upper left corner of the days of the month and I want to put a picture next to the day.
How can I do this?
Thanks.
Using hard coded number of month is an error. By doing this your calendar will be wrong on bisextil years. For exemple try february 2012, you display only 28 days whereas in 2012 february has 29 days.
Anyway your article help me a lot ! Thanks
Hi,
Passing from 2011 to 2012 display 32 days of January in Calendar. How can we solve?
Thanks.
Hi!
THANK YOU for this calendar.
I’ve got some questions to ask you about the code. Can I have your email please? I see you mention in the comments email me but I can’t see your email!
Thanks.
The 34KB SimpleCalendarImp.zip is corrupted. Please email me at jwaterloo@dynamicquest.com
Hi …
i am new to android, i want highlight multiple particular date in calendar. how can i achive this one.. can u help me please
Hi this is very helpfull..
but i can download android project from fileFactory.
can you send me the project wuqq2007@yahoo.cn
thank you very much….
Could you please mail the project to prasad.varna@gmail.com…I’m not bale to download the project from the link provided above.
Pls help me.My emailId is prasad.varna@gmail.com
Hi.
I’m a newbiw in Android.Thank you so much for this sample.Its really very helpful.
Im not able to download this project from the link given above,
It will be of great help to me if you can mail the project to prasad.varna@gmail.com.
Thanks
Thank you for this very useful sample calendar.
It helps me a lot.
Is it okay if I had a problem later on developing this app, I will post it here?
Hello,thank you for support this.
Is it posible to put monday first day of calendar?
I setCalendarFirstDayOfWeek but draw firat day sunday
Thanks for all
Search for line:
trailingSpaces = currentWeekDay;
and replace with:
int[] weekDaysToTraling = { 6, 0, 5, 4, 3, 2, 1 };
trailingSpaces = weekDaysToTraling[currentWeekDay];
Sorry, wrong array. Try this: { 6, 0, 1, 2, 3, 4, 5 } 😉
@Admin: Please delete these two posts here… I answered to the newest post at the bottom… Thanks.
The download link to SimpleCalendarImp.zip on the File Factory website doesn’t seem to work
Hi,
Hi,
I have all my code uploaded as zip files at github.com
Here is the link: https://github.com/w2davids/Ghostdrive
and for cloning my repo – use/install git and use the following command :
git clone git@github.com:w2davids/Ghostdrive.git
Thanks a lot sir!
I’m not sure if I’m the only one experiencing this but January 2012 has day 32.
Also with 2016, looks like this is happening only on leap years.
Commenting these out did the trick.
/*if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == 1) {
++daysInMonth;
}*/
Instead of commenting it out, change it to actually work
if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == 2) {
++daysInMonth;
}
@zalez You are right! Thanks! ^^
You must add this too.
// Trailing Month days
for (int i = 0; i ” + getMonthAsString(prevMonth) + ” ” + String.valueOf((daysInPrevMonth – trailingSpaces + DAY_OFFSET) + i + 1));
list.add(String.valueOf((daysInPrevMonth – trailingSpaces + DAY_OFFSET) + i + 1) + “-GREY” + “-” + getMonthAsString(prevMonth) + “-” + prevYear);
}
else
{
Log.d(tag, “PREV MONTH:= ” + prevMonth + ” => ” + getMonthAsString(prevMonth) + ” ” + String.valueOf((daysInPrevMonth – trailingSpaces + DAY_OFFSET) + i));
list.add(String.valueOf((daysInPrevMonth – trailingSpaces + DAY_OFFSET) + i) + “-GREY” + “-” + getMonthAsString(prevMonth) + “-” + prevYear);
}
}
Thanks a lot for this calendar!
Please delete my previous post, it’s wrong.
You must add this too.
// Trailing Month days
for (int i = 0; i ” + getMonthAsString(prevMonth) + ” ” + String.valueOf((daysInPrevMonth – trailingSpaces + DAY_OFFSET) + i + 1));
list.add(String.valueOf((daysInPrevMonth – trailingSpaces + DAY_OFFSET) + i + 1) + “-GREY” + “-” + getMonthAsString(prevMonth) + “-” + prevYear);
}
else
{
Log.d(tag, “PREV MONTH:= ” + prevMonth + ” => ” + getMonthAsString(prevMonth) + ” ” + String.valueOf((daysInPrevMonth – trailingSpaces + DAY_OFFSET) + i));
list.add(String.valueOf((daysInPrevMonth – trailingSpaces + DAY_OFFSET) + i) + “-GREY” + “-” + getMonthAsString(prevMonth) + “-” + prevYear);
}
}
Thanks a lot for this calendar!
Last attempt. Please delete my previous posts, they’re wrong.
You must add this too.
// Trailing Month days
for (int i = 0; i < trailingSpaces; i++)
{
if (cal.isLeapYear(cal.get(Calendar.YEAR)) && mm == Calendar.MARCH + 1)
{
list.add(String.valueOf((daysInPrevMonth – trailingSpaces + DAY_OFFSET) + i + 1) + "-GREY" + "-" + getMonthAsString(prevMonth) + "-" + prevYear);
}
else
{
list.add(String.valueOf((daysInPrevMonth – trailingSpaces + DAY_OFFSET) + i) + "-GREY" + "-" + getMonthAsString(prevMonth) + "-" + prevYear);
}
}
Thanks a lot for this calendar!
@w2davids
This error is really bad, zalez corrected it, can you update your code by replacing your if with zalez’s code.
@Viketig
Can you specify why we must add your code?
Viketig is absolutely correct, you do need that code. The reason is that, although Zalez’ solution does fix the current month (February 2012), if you check the next month (March 2012) the trailing days appear a day behind, meaning Wednesday shows up as the 28 when it has been correctly fixed to be the 29th as it is in February. Viketig’s code fixes that discrepancy, so with the two combined code snippets, there are no further errors in the leap year calculation.
thanks a lot man look promising and running great.
Hi
Im not able to download this project from the link given above,
It will be of great help to me if you can mail the project to bharadwaja.prashi@gmail.com.
Great tutorial, thanks a lot!
how to add onclick listener to gridcells,i want to set listener for every day
i cant run the project …. im learning andriod and i am new to this.. can any one tell me how to run this? there are so many errors in the activity file… it says:
cactivity can not be resolved to a type….
Looks like what I’ve been looking for. Can I use it in my own app? I’m not entirely sure about all that licensing stuff!
Thanks
thnx alot for your for your project ,
i dont want to use SQLite ,
cant i put the events of some selected days in .xml file ?
and then get them ? if it’s possible what the code would be ?
thnx for ur help in advance
I’m having a weird problem where the greyed out days for the next and previous months use the num_events for the current month days. So, if the user’s current month is December and the 30th has an event, it will show November as having an event on the 30th even if there is not.
I’ll try and fix it, but I’m hoping someone has already done so! Thanks
@Adam
I have the same exact problem!!! Did you solve it ?
OK, I think I solved it (dirty way, but it seems to work! 😉 )
Inside getview() I wrote down this code:
currentMonth = (Button) CalendarioActivity.this.findViewById(R.id.currentMonth);
String mycurrentMonth = currentMonth.getText().toString();
String[] arr = mycurrentMonth.split(“\\s|,”);
In this way I store the String “December” (the current month) in arr[0].
Now I modified the line :
if (eventsPerMonthMap.containsKey(theday) )
into
if (eventsPerMonthMap.containsKey(theday) && themonth.equals(arr[0]) )
SEEMS to work! 😉
it didn’t work for me, I just don’t understand the word after mycurrentMonth.split(“blabla”)
does anyone want to help me?
thanks.
I have a problem about implement this calendar.
the first problem is on February 2012, the date is shown as 28, that should be 29, but it still consistent in March that the 1st date is begin on Thursday.
the second problem is when the 1st date begin on Saturday, the 31st date is not shown, because the default row is 5.
Please help.
thank you.
IgnatiusAdityaSetyadi@yahoo.com
Sorry, It already works well on me.
But I have another problem when I try it on my Android phone.
When It run in portrait, the calendar header (Sun, Mon, Tue, Wed, Thu, Fri, Sat) show good, but not match when we try to rotate in landscape, maybe it because the Calendar header is just an image.
Does anyone want to help me to solve this problem? at least try to change the calendar header from image that can be match in portrait or landscape.
Thanks in advance.
Cannot download SimpleCalendarImp.zip. please email me the file to omarica2006@gmail.com
i am developing a program . where it has a calender , when the user presses on the date the event shows up .
please anyone post the code for adding events to a date (for above program)
This calendar first day is Sunday. I want to put the first day Monday. How can I do this? Thanks.
Search for line:
trailingSpaces = currentWeekDay;
and replace with:
int[] weekDaysToTraling = { 6, 0, 1, 2, 3, 4, 5 };
trailingSpaces = weekDaysToTraling[currentWeekDay];
Thank you very much Jordan, it was worked.
What if I want to display the dates from the right to the left?
Such as:
{.. ,9,8,7,6,4,3,2,1}
instead of:
{1,2,3,4,5,6,7,8,9,…}
Thanks a lot.
What if I want the dates to appear from right to left.
Such as {…9,8,7,6,5,4,3,2,1} instead of {1,2,3,4,5,6,7,8,9,..}
What should I change in the code?
Thanks.
how can i add events on each day? thanks i’m a newbie, sorry for that
can some one tell me how to add a event to this calendar
how can i add event in a specific date? anyone please? i’m a beginner, sorry for that. Thanks in advance.
can u please guide me how to display calendar view by week per month .. It would be great favor.
A begginer at android programing, can you run this in the emulator?
Thanks
Good article, but FileFactory is horrible place to place your download. You just can’t download it unless you buy their premium service. Down Vote for that.
how can i add an event in a specific date? anyone? thanks in advance. 🙂