Android Calendar Layout

Question!

My calendar layout looks something like this:

A B C D E F G

A B C D E F G

A B C D E F G

A B C D

I would like to make it that the first day of the calendar to start, for example, from the forth element's position (this implementation should be available only for the first row of the calendar) like this:

 blank A B C D

A B C D E F

A B C D E F

A B C D E F

I have a GridView for this, which is is using a RelativeLayout with a Button in it that has as a background another layout, that shouldn't be relevant right now.

Any advice...? Thanks :)



Answers
You this function while before you notifies you data set change.

public void refreshDays() {
        // clear items
        items.clear();
        flagDepartureDate = false;
        flagArrivalDate = false;

        int lastDay = month.getActualMaximum(Calendar.DAY_OF_MONTH);
        int firstDay = month.get(Calendar.DAY_OF_WEEK);

        Calendar temp = (Calendar) month.clone();
        temp.add(Calendar.MONTH, -1);

        Calendar temp2 = (Calendar) month.clone();
        temp2.add(Calendar.MONTH, +1);

        int lastDay_prev = temp.getActualMaximum(Calendar.DAY_OF_MONTH);

        /*
         * if(((firstDay-1)+lastDay)>35) {
         */
        calDay.days = new String[42];
        calDay.month = new int[42];
        calDay.year = new int[42];
        /*
         * } else{ calDay.days = new String[35]; calDay.month = new int[35];
         * calDay.year = new int[35]; }
         */

        // Log.i("LAST DAY", lastDay+"");
        // Log.i("LAST DAY PREV", lastDay_prev+"");
        // Log.i("FIRST DAY", firstDay+"");
        // Log.i("FIRST_DAY_OF_WEEK", FIRST_DAY_OF_WEEK+"");
        int start_blanks = 0;
        int j = FIRST_DAY_OF_WEEK;

        // populate empty days before first real day
        if (firstDay > 1) {
            for (j = 0; j < firstDay - FIRST_DAY_OF_WEEK - 1; j++) {

                calDay.days[j] = ""
                        + (lastDay_prev - (firstDay - FIRST_DAY_OF_WEEK - 1)
                                + j + 1);
                calDay.month[j] = temp.get(Calendar.MONTH);
                calDay.year[j] = temp.get(Calendar.YEAR);
                start_blanks += 1;
            }
        } else {
            for (j = 0; j < FIRST_DAY_OF_WEEK * 6; j++) {
                calDay.days[j] = "";
            }
            j = FIRST_DAY_OF_WEEK * 6; // sunday => 1, monday => 7
        }
        // Log.i("START_BLANK", start_blanks+"");
        // populate days
        int dayNumber = 1;
        for (int i = j; i < (lastDay + start_blanks); i++) {
            calDay.days[i] = "" + dayNumber;
            calDay.month[i] = month.get(Calendar.MONTH);
            calDay.year[i] = month.get(Calendar.YEAR);
            dayNumber++;
        }

        // populate empty days before first real day
        for (int i = (lastDay + start_blanks), k = 1; i < calDay.days.length; i++, k++) {
            calDay.days[i] = "" + k;
            calDay.month[i] = temp2.get(Calendar.MONTH);
            calDay.year[i] = temp2.get(Calendar.YEAR);
        }

    }

Here "month" is the object of current calendar month

By : Jigar


Sign up using Google



This video can help you solving your question :)
By: admin