Showing calendar months in a Year in Android

12 min read

Hi

Few days earlier I encountered with a software problem for android in which I have to show a calendar months in a year (eg 2016) refer below image.

2016-04-03

Initial Solution

Layout xml file

<LinearLayout

    android:id=”@+id/bgtoplevel”

    xmlns:android=”http://schemas.android.com/apk/res/android”

    android:layout_width=”match_parent”

    android:layout_height=”match_parent”

    android:background=”#ac060606″

    android:padding=”2dp”

    android:orientation=”vertical”>

    <LinearLayout

        android:id=”@+id/lltwo”

        android:orientation=”vertical”

        android:gravity=”center_horizontal”

        android:layout_width=”match_parent”

        android:layout_height=”match_parent” >

        <TextView

            android:background=”#896d03d1″

            android:text=”MONTH NAME”

            android:gravity=”center”

            android:textColor=”#FFFFFF”

            android:id=”@+id/calViewTitleYear”

            android:layout_width=”match_parent”

            android:layout_height=”50dp”/>

        <GridView

            android:layout_marginTop=”4dp”

            android:id=”@+id/gridview”

            android:layout_width=”match_parent”

            android:layout_height=”wrap_content”

            android:columnWidth=”100dp”

            android:numColumns=”6″

            android:stretchMode=”columnWidth”

            android:horizontalSpacing=”10dp”

            android:verticalSpacing=”20dp”>

        </GridView>

    </LinearLayout>

</LinearLayout>

 

 

Layout file for Gridview Items

<LinearLayout

    android:id=”@+id/bgtoplevel”

    xmlns:android=”http://schemas.android.com/apk/res/android”

    android:layout_width=”wrap_content”

    android:layout_height=”wrap_content”

    android:orientation=”vertical”>

    <TextView

        android:background=”#896d03d1″

        android:text=”MONTH NAME”

        android:textColor=”#FFFFFF”

        android:id=”@+id/calViewTitleYear”

        android:layout_width=”180dp”

        android:layout_height=”wrap_content”/>

    <GridView

        android:background=”@drawable/year_grid_item”

        android:id=”@+id/gridviewinner”

        android:layout_width=”180dp”

        android:layout_height=”160dp”

        android:columnWidth=”4dp”

        android:gravity=”center”

        android:numColumns=”7″

        android:stretchMode=”columnWidth”

        android:verticalSpacing=”2dp”>

    </GridView>

</LinearLayout>

 

Java Files

We will create a YearView Fragment

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.relsell.bmc.app.R;
import com.relsell.bmc.app.yearlyholiday.month.MonthViewMain;

import java.util.ArrayList;
import java.util.Calendar;

/**
 * Created by anilkukreti on 10/12/15.
 */
public class AndroidYearlyCalendarViewFragment extends Fragment {

    private GridView mGridView;
    private YearGridAdapter mAdapter;
    private TextView mTextView;
    private int mYear;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // get initial calendar year from bundle
        setRetainInstance(true);

        Bundle b = getArguments();
        mYear = b.getInt("intialCalendarYear");

    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View v = inflater.inflate(R.layout.calendarview_yearlyview, null);

        mTextView = (TextView)v.findViewById(R.id.calViewTitleYear);

        mGridView = (GridView)v.findViewById(R.id.gridview);

        return v;
    }


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        mTextView.setText("" + mYear);

        ArrayList arrList = new ArrayList();
        arrList.add("JANUARY");
        arrList.add("FEB");
        arrList.add("MARCH");
        arrList.add("APRIL");
        arrList.add("MAY");
        arrList.add("JUNE");
        arrList.add("JULY");
        arrList.add("AUGUST");
        arrList.add("SEPTEMBER");
        arrList.add("OCTOBER");
        arrList.add("NOVEMBER");
        arrList.add("DECEMBER");
        mAdapter = new YearGridAdapter(getActivity(),arrList,mGridView,mYear);
        mGridView.setAdapter(mAdapter);
    }
}

Year Grid Adapter

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.relsell.bmc.app.R;
import com.relsell.bmc.app.bluetoohinteraction.BluetoothInteractionActivity;
import com.relsell.bmc.app.checklog.CheckLogActivity;
import com.relsell.bmc.app.logemailsetup.MailSender;
import com.relsell.bmc.app.yearlyholiday.month.MonthViewMain;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Relsell Global on 30/10/15.
 */
public class YearGridAdapter extends BaseAdapter{

    private Context mContext;
    private ArrayList mList;
    private GridView mGridView;
    private int mYear;
    private YearInnerGridAdapter mAdapter;


    public YearGridAdapter(Context context, ArrayList list, GridView gridView,int year) {

        mContext = context;
        mList = list;
        mGridView = gridView;
        this.mYear = year;
    }

    @Override
    public int getCount() {
        int size = mList != null ? mList.size():0;
        return size;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final int pos = position;
        ViewHolder holder = null;
        if(convertView == null) {
            holder = new ViewHolder();
            LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = (View)li.inflate(R.layout.calendarview_year_gridview_alt_items, null);
            holder.calendarLL = (LinearLayout)convertView.findViewById(R.id.bgtoplevel);
            holder.imageView = (ImageView)convertView.findViewById(R.id.imageView);
            //holder.innerGridView =  (GridView)convertView.findViewById(R.id.gridviewinner);
            holder.mCaldendarTitleView = (TextView)convertView.findViewById(R.id.calViewTitleYear);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }

        holder.mCaldendarTitleView.setText(mList.get(position));





        ArrayList arrList;


        int year = mYear;

        boolean isLeapYear = false;

        //if year is divisible by 4, it is a leap year

        if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
            isLeapYear = true;
        }
        else {
            isLeapYear = false;
        }

        if(mList.get(position).equalsIgnoreCase("FEB")) {

            if(isLeapYear) {
                arrList = new ArrayList();
                for(int i=0; i < 29;i++) {
                    arrList.add(i+1);
                }
                holder.imageView.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.calendar_image_twenty_nine));
            }else {
                arrList = new ArrayList();
                for (int i = 0; i < 28; i++) {
                    arrList.add(i + 1);
                }
                holder.imageView.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.calendar_image_twenty_eight));
            }
        } else if(mList.get(position).equalsIgnoreCase("JANUARY") || mList.get(position).equalsIgnoreCase("MARCH") || mList.get(position).equalsIgnoreCase("MAY") || mList.get(position).equalsIgnoreCase("JULY")|| mList.get(position).equalsIgnoreCase("AUGUST") || mList.get(position).equalsIgnoreCase("OCTOBER") || mList.get(position).equalsIgnoreCase("DECEMBER")){
            arrList = new ArrayList();
            for(int i=0; i<31;i++) {
                arrList.add(i+1);
            }

            holder.imageView.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.calendar_image_three_one));


        } else {
            arrList = new ArrayList();
            for(int i=0; i<30;i++) {
                arrList.add(i+1);
            }

            holder.imageView.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.calendar_image_thirty));
        }







        //mAdapter = new YearInnerGridAdapter(mContext,arrList,mGridView,mYear);
        //holder.innerGridView.setAdapter(mAdapter);





        holder.calendarLL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                int selectedMonth = 0;

                String sM = mList.get(pos);
                if(sM.equalsIgnoreCase("JANUARY")) {
                    selectedMonth = 0;
                } else if(sM.equalsIgnoreCase("FEB")) {
                    selectedMonth = 1;
                }  else if(sM.equalsIgnoreCase("MARCH")) {
                    selectedMonth = 2;
                }  else if(sM.equalsIgnoreCase("APRIL")) {
                    selectedMonth = 3;
                }  else if(sM.equalsIgnoreCase("MAY")) {
                    selectedMonth = 4;
                }  else if(sM.equalsIgnoreCase("JUNE")) {
                    selectedMonth = 5;
                }  else if(sM.equalsIgnoreCase("JULY")) {
                    selectedMonth = 6;
                }  else if(sM.equalsIgnoreCase("AUGUST")) {
                    selectedMonth = 7;
                }  else if(sM.equalsIgnoreCase("SEPTEMBER")) {
                    selectedMonth = 8;
                }  else if(sM.equalsIgnoreCase("OCTOBER")) {
                    selectedMonth = 9;
                }  else if(sM.equalsIgnoreCase("NOVEMBER")) {
                    selectedMonth = 10;
                }  else if(sM.equalsIgnoreCase("DECEMBER")) {
                    selectedMonth = 11;
                }

                Intent i = new Intent(mContext, MonthViewMain.class);
                i.putExtra("selectedMonth",selectedMonth);
                i.putExtra("intialCalendarYear",mYear);
                mContext.startActivity(i);
            }
        });




        return convertView;
    }

    public static class ViewHolder {
        LinearLayout calendarLL;
        GridView innerGridView;
        ImageView imageView;
        TextView mCaldendarTitleView;
    }
}

Problem with above solution is that it works but it is very slow to load in turns it affects User experience. So i think we need to find different solution. Lets create our griditems file as Table layout and TextViews rather than smaller gridviews and innergriditems.




 

Final Solution

<LinearLayout

            android:layout_width=”match_parent”

            android:layout_height=”match_parent”

            android:paddingLeft=”@dimen/activity_horizontal_margin”

            android:paddingRight=”@dimen/activity_horizontal_margin”

            android:paddingTop=”@dimen/activity_vertical_margin”

            >

            <GridView

                android:id=”@+id/gridView”

                android:layout_width=”match_parent”

                android:layout_height=”wrap_content”

                android:horizontalSpacing=”10dp”

                android:numColumns=”3″

                android:verticalSpacing=”10dp”/>

        </LinearLayout></pre>

Our gridview items layout

<pre class=”EnlighterJSRAW” data-enlighter-language=”java”>

<TableLayout

        xmlns:android=”http://schemas.android.com/apk/res/android”

        android:id=”@+id/tableLayout1″

        android:background=”#FFFFFF”

        android:layout_width=”match_parent”

        android:layout_height=”match_parent”

        android:padding=”2dp”

        android:shrinkColumns=”*”

        android:stretchColumns=”*”>

        <TableRow

            android:id=”@+id/tableRow2″

            android:layout_width=”match_parent”

            android:layout_height=”wrap_content”

            android:gravity=”center_horizontal”>

            <TextView

                android:id=”@+id/tvR2C1″

                style=”@style/calendar_month”

                android:layout_width=”wrap_content”

                android:layout_height=”wrap_content”

                android:layout_span=”7″

                android:text=”@string/month_title_1″/>

        </TableRow>

        <TableRow

            android:id=”@+id/tableRow4″

            android:layout_width=”match_parent”

            android:layout_height=”wrap_content”

            android:gravity=”center_horizontal”>

            <TextView

                android:id=”@+id/tvR4C1″

                style=”@style/calendar_date.sun”

                android:text=”S”/>

            <TextView

                android:id=”@+id/tvR4C2″

                style=”@style/calendar_date”

                android:text=”M”/>

            <TextView

                android:id=”@+id/tvR4C3″

                style=”@style/calendar_date”

                android:text=”T”/>

            <TextView

                android:id=”@+id/tvR4C4″

                style=”@style/calendar_date”

                android:text=”W”/>

            <TextView

                android:id=”@+id/tvR4C5″

                style=”@style/calendar_date”

                android:text=”T”/>

            <TextView

                android:id=”@+id/tvR4C6″

                style=”@style/calendar_date”

                android:text=”F”/>

            <TextView

                android:id=”@+id/tvR4C7″

                style=”@style/calendar_date.sat”

                android:text=”S”/>

        </TableRow>

        <TableRow

            android:id=”@+id/tableRow5″

            android:layout_width=”fill_parent”

            android:layout_height=”wrap_content”

            android:gravity=”center_horizontal”>

            <TextView

                android:id=”@+id/tvR5C1″

                style=”@style/calendar_date.sun”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR5C2″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR5C3″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR5C4″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR5C5″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR5C6″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR5C7″

                style=”@style/calendar_date.sat”

                android:text=”@string/date_x”/>

        </TableRow>

        <TableRow

            android:id=”@+id/tableRow6″

            android:layout_width=”fill_parent”

            android:layout_height=”wrap_content”

            android:gravity=”center_horizontal”>

            <TextView

                android:id=”@+id/tvR6C1″

                style=”@style/calendar_date.sun”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR6C2″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR6C3″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR6C4″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR6C5″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR6C6″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR6C7″

                style=”@style/calendar_date.sat”

                android:text=”@string/date_x”/>

        </TableRow>

        <TableRow

            android:id=”@+id/tableRow7″

            android:layout_width=”fill_parent”

            android:layout_height=”wrap_content”

            android:gravity=”center_horizontal”>

            <TextView

                android:id=”@+id/tvR7C1″

                style=”@style/calendar_date.sun”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR7C2″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR7C3″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR7C4″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR7C5″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR7C6″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR7C7″

                style=”@style/calendar_date.sat”

                android:text=”@string/date_x”/>

        </TableRow>

        <TableRow

            android:id=”@+id/tableRow8″

            android:layout_width=”fill_parent”

            android:layout_height=”wrap_content”

            android:gravity=”center_horizontal”>

            <TextView

                android:id=”@+id/tvR8C1″

                style=”@style/calendar_date.sun”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR8C2″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR8C3″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR8C4″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR8C5″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR8C6″

                style=”@style/calendar_date”

                android:text=”@string/date_x”/>

            <TextView

                android:id=”@+id/tvR8C7″

                style=”@style/calendar_date.sat”

                android:text=”@string/date_x”/>

        </TableRow>

        <TableRow

        android:id=”@+id/tableRow9″

        android:layout_width=”fill_parent”

        android:layout_height=”wrap_content”

        android:gravity=”center_horizontal”>

        <TextView

            android:id=”@+id/tvR9C1″

            style=”@style/calendar_date.sun”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR9C2″

            style=”@style/calendar_date”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR9C3″

            style=”@style/calendar_date”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR9C4″

            style=”@style/calendar_date”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR9C5″

            style=”@style/calendar_date”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR9C6″

            style=”@style/calendar_date”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR9C7″

            style=”@style/calendar_date.sat”

            android:text=”@string/date_x”/>

    </TableRow>

        <TableRow

        android:id=”@+id/tableRow10″

        android:layout_width=”fill_parent”

        android:layout_height=”wrap_content”

        android:gravity=”center_horizontal”>

        <TextView

            android:id=”@+id/tvR10C1″

            style=”@style/calendar_date.sun”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR10C2″

            style=”@style/calendar_date”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR10C3″

            style=”@style/calendar_date”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR10C4″

            style=”@style/calendar_date”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR10C5″

            style=”@style/calendar_date”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR10C6″

            style=”@style/calendar_date”

            android:text=”@string/date_x”/>

        <TextView

            android:id=”@+id/tvR10C7″

            style=”@style/calendar_date.sat”

            android:text=”@string/date_x”/>

    </TableRow>

    </TableLayout>

 

 

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

import com.relsell.bmc.app.R;

import java.util.ArrayList;
import java.util.Calendar;

/**
 * Created by Relsell Global on 30/10/15.
 */
public class GridAdapter extends BaseAdapter {

    private Context mContext;
    private GridView mGridView;
    String recipientAddress = "";
    int mGridItemBgResId;
    int startingDayIndex;



    public GridAdapter(Context context, GridView gridView,int startIndex) {

        mContext = context;
        mGridView = gridView;
        this.startingDayIndex = startIndex;
    }

    @Override
    public int getCount() {
        return 12;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final int pos = position;
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = (View) li.inflate(R.layout.activity_main_calendar_single_month, null);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        modifyDataForMonth(convertView,pos);
        return convertView;
    }

    public static class ViewHolder {
        ImageView btn;
    }

    public void modifyDataForMonth(View v,int month) {

        TextView row2C1 = (TextView)v.findViewById(R.id.tvR2C1);
        int majicStartIndex = -1;

        Calendar c = null;
        int startIndex = -1;

        switch(month) {
            case 0:
                row2C1.setText("JAN");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR, 2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 1:
                row2C1.setText("FEB");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 2:
                row2C1.setText("MAR");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 3:
                row2C1.setText("APR");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 4:
                row2C1.setText("MAY");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 5:
                row2C1.setText("JUN");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 6:
                row2C1.setText("JUL");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 7:
                row2C1.setText("AUG");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 8:
                row2C1.setText("SEP");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 9:
                row2C1.setText("OCT");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 10:
                row2C1.setText("NOV");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
            case 11:
                row2C1.setText("DEC");
                c = Calendar.getInstance();
                c.set(Calendar.YEAR,2016);
                c.set(Calendar.MONTH,month);
                c.set(Calendar.DATE, 0);
                startIndex = c.get(Calendar.DAY_OF_WEEK);
                break;
        }

        if(startIndex >=7) {
            startIndex = 0;
        }


        if(startIndex >=0 && startIndex<=6) {

            TextView row5C1 = (TextView)v.findViewById(R.id.tvR5C1);
            TextView row5C2 = (TextView)v.findViewById(R.id.tvR5C2);
            TextView row5C3 = (TextView)v.findViewById(R.id.tvR5C3);
            TextView row5C4 = (TextView)v.findViewById(R.id.tvR5C4);
            TextView row5C5 = (TextView)v.findViewById(R.id.tvR5C5);
            TextView row5C6 = (TextView)v.findViewById(R.id.tvR5C6);
            TextView row5C7 = (TextView)v.findViewById(R.id.tvR5C7);

            ArrayList row5 = new ArrayList<>();
            row5.add(row5C1);
            row5.add(row5C2);
            row5.add(row5C3);
            row5.add(row5C4);
            row5.add(row5C5);
            row5.add(row5C6);
            row5.add(row5C7);


            int k6 = stuffRow5(startIndex, row5);

            TextView row6C1 = (TextView) v.findViewById(R.id.tvR6C1);
            TextView row6C2 = (TextView) v.findViewById(R.id.tvR6C2);
            TextView row6C3 = (TextView) v.findViewById(R.id.tvR6C3);
            TextView row6C4 = (TextView) v.findViewById(R.id.tvR6C4);
            TextView row6C5 = (TextView) v.findViewById(R.id.tvR6C5);
            TextView row6C6 = (TextView) v.findViewById(R.id.tvR6C6);
            TextView row6C7 = (TextView) v.findViewById(R.id.tvR6C7);

            ArrayList row6 = new ArrayList<>();
            row6.add(row6C1);
            row6.add(row6C2);
            row6.add(row6C3);
            row6.add(row6C4);
            row6.add(row6C5);
            row6.add(row6C6);
            row6.add(row6C7);
            int k7 = stuffRow(k6, row6);


            TextView row7C1 = (TextView) v.findViewById(R.id.tvR7C1);
            TextView row7C2 = (TextView) v.findViewById(R.id.tvR7C2);
            TextView row7C3 = (TextView) v.findViewById(R.id.tvR7C3);
            TextView row7C4 = (TextView) v.findViewById(R.id.tvR7C4);
            TextView row7C5 = (TextView) v.findViewById(R.id.tvR7C5);
            TextView row7C6 = (TextView) v.findViewById(R.id.tvR7C6);
            TextView row7C7 = (TextView) v.findViewById(R.id.tvR7C7);

            ArrayList row7 = new ArrayList<>();
            row7.add(row7C1);
            row7.add(row7C2);
            row7.add(row7C3);
            row7.add(row7C4);
            row7.add(row7C5);
            row7.add(row7C6);
            row7.add(row7C7);

            int k8 = stuffRow(k7, row7);

            TextView row8C1 = (TextView) v.findViewById(R.id.tvR8C1);
            TextView row8C2 = (TextView) v.findViewById(R.id.tvR8C2);
            TextView row8C3 = (TextView) v.findViewById(R.id.tvR8C3);
            TextView row8C4 = (TextView) v.findViewById(R.id.tvR8C4);
            TextView row8C5 = (TextView) v.findViewById(R.id.tvR8C5);
            TextView row8C6 = (TextView) v.findViewById(R.id.tvR8C6);
            TextView row8C7 = (TextView) v.findViewById(R.id.tvR8C7);

            ArrayList row8 = new ArrayList<>();
            row8.add(row8C1);
            row8.add(row8C2);
            row8.add(row8C3);
            row8.add(row8C4);
            row8.add(row8C5);
            row8.add(row8C6);
            row8.add(row8C7);

            int k9 = stuffRow(k8, row8);

            TextView row9C1 = (TextView) v.findViewById(R.id.tvR9C1);
            TextView row9C2 = (TextView) v.findViewById(R.id.tvR9C2);
            TextView row9C3 = (TextView) v.findViewById(R.id.tvR9C3);
            TextView row9C4 = (TextView) v.findViewById(R.id.tvR9C4);
            TextView row9C5 = (TextView) v.findViewById(R.id.tvR9C5);
            TextView row9C6 = (TextView) v.findViewById(R.id.tvR9C6);
            TextView row9C7 = (TextView) v.findViewById(R.id.tvR9C7);

            ArrayList row9 = new ArrayList<>();
            row9.add(row9C1);
            row9.add(row9C2);
            row9.add(row9C3);
            row9.add(row9C4);
            row9.add(row9C5);
            row9.add(row9C6);
            row9.add(row9C7);

            int k10 = stuffRow(k9, row9);

            TextView row10C1 = (TextView) v.findViewById(R.id.tvR10C1);
            TextView row10C2 = (TextView) v.findViewById(R.id.tvR10C2);
            TextView row10C3 = (TextView) v.findViewById(R.id.tvR10C3);
            TextView row10C4 = (TextView) v.findViewById(R.id.tvR10C4);
            TextView row10C5 = (TextView) v.findViewById(R.id.tvR10C5);
            TextView row10C6 = (TextView) v.findViewById(R.id.tvR10C6);
            TextView row10C7 = (TextView) v.findViewById(R.id.tvR10C7);

            ArrayList row10 = new ArrayList<>();
            row10.add(row10C1);
            row10.add(row10C2);
            row10.add(row10C3);
            row10.add(row10C4);
            row10.add(row10C5);
            row10.add(row10C6);
            row10.add(row10C7);

            int k11 = stuffRow(k10, row10);
        }



    }
    public int stuffRow5(int index,ArrayList row) {

        int j = 1;
        int p = index;
        for(int i=0,rowVar = 0; i0) {
                TextView tv = row.get(rowVar);
                tv.setText(" ");
                i++;
                rowVar++;
            }
            TextView tv = row.get(rowVar);
            tv.setText(""+j);
        }
        return j;

    }

    public int stuffRow(int j,ArrayList row) {
        for(int i=0,rowVar = 0;i