Sidious911
Sidious911

Reputation: 73

Android grid layout for custom calendar

I'm working on a project that is going to require our own custom calendar view. I've been trying to figure out the best way to approach this. I was considering possibly using a Master xml file that will define the basic layout of the calendar, and then use a secondary xml file, and nest it into each cell of the calendar for each day as an array of objects.

Not exactly sure if this is possible, or if this would be the best way to approach this problem?

Cheers

Upvotes: 0

Views: 2458

Answers (2)

palaniraja
palaniraja

Reputation: 10492

Android has a util for doing all the math to find the days in a month. I guess using a gridview with android.util.MonthDisplayHelper should work.

Upvotes: 0

kaspermoerch
kaspermoerch

Reputation: 16570

I recently created a Month layout, using TableLayout.

I took into consideration that you will need 6x7 days for a month to be able to handle every possible situation. (First day of the month being a sunday, last day of the month being a monday etc.)

Based on a given date (lets say 3rd of August) I calculate the first day to be shown

date = 3rd of August
firstDate = first day of month based on date
while( firstDate is not a monday )
   firstDate = present date

I then calculate the last day to be shown:

lastDate = last day of month based on date
while( lastDate is not a Sunday )
   lastDay = following date

This gives me an interval of dates from firstDate to lastDate

Then I programaticly create 6 TableRow's in which there are 7 days - a TextView or whatever. It could just be declared in an XML-file if you don't want to create too much layout on the fly. One thing to remember is to set the layout_weight for the TextViews so that they are all equally big/small to create a nice grid.

If what you need is more like a Day- or Weeklayout the challenge is a little tougher.

Upvotes: 1

Related Questions