Monday, December 24, 2012

ListView into ScrollView in Android

Hello Friends!
Today I am going to share very important code for ListView into ScrollView.
Many Android developers says: You should not put a ListView in a ScrollView because a ListView already a scrollview.

 But some times its really needed in project “ how can place a ListView into a ScrollView without it collapsing to its minimum height?

And finally I got it on stack over flow-

waste a lot of time in goggling so I don’t want some one do same so you can follow my blog 
step by step-

UPDATE: Please check my this post for in case any of issue-
http://www.androidhub4you.com/2014/03/android-listview-into-scrollview-issue.html

PrintScren:


Step1- Create an Activity name-MainActivity.java and create a listview.

package com.example.scrollviewlistviewdemo;

import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {
       private String listview_array[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE",
                     "SIX", "SEVEN", "EIGHT", "NINE", "TEN" };
       ListView myList;

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);

              myList = (ListView) findViewById(R.id.listView);
              myList.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, listview_array));
              Helper.getListViewSize(myList);
      
       }
}
Step2- Create main.xml-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="19dp"
            android:text="@string/hello_world" />

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/ic_launcher" />

        <ListView
            android:id="@+id/listView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

</ScrollView>

Step3- Finally and important thing create another class Helper.java and put below given code-
package com.example.scrollviewlistviewdemo;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

public class Helper {
    public static void getListViewSize(ListView myListView) {
        ListAdapter myListAdapter = myListView.getAdapter();
        if (myListAdapter == null) {
            //do nothing return null
            return;
        }
        //set listAdapter in loop for getting final size
        int totalHeight = 0;
        for (int size = 0; size < myListAdapter.getCount(); size++) {
            View listItem = myListAdapter.getView(size, null, myListView);
            listItem.measure(0, 0);
            totalHeight += listItem.getMeasuredHeight();
        }
      //setting listview item in adapter
        ViewGroup.LayoutParams params = myListView.getLayoutParams();
        params.height = totalHeight + (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
        myListView.setLayoutParams(params);
        // print height of adapter on log
        Log.i("height of listItem:", String.valueOf(totalHeight));
    }
}

Hope it will help you thanks!

Thursday, December 20, 2012

Custom Alert Dialog Title and Message Demo in Android


Hi Friends!
      Today I am sharing simple code for custom alert message and title demo...

1)Print Screen:

2)Code:
package com.example.customalertmessagedemo;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Color;
import android.view.Gravity;
import android.widget.TextView;

public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        // Creates textview for centre title
TextView myMsg = new TextView(this);
myMsg.setText("Succesfully send!");
myMsg.setGravity(Gravity.CENTER_HORIZONTAL);
myMsg.setTextSize(20);
myMsg.setTextColor(Color.WHITE);
//set custom title
        builder.setCustomTitle(myMsg);
        builder.setMessage("Check your email and verify your username and password...");
        builder.setPositiveButton("OK", null);
        AlertDialog dialog = builder.show();
        //Create custom message
        TextView messageText = (TextView)dialog.findViewById(android.R.id.message);
        messageText.setGravity(Gravity.CENTER);
    }
}



Thanks...

Monday, October 29, 2012

Flip Animation in Android | Flip demo in Android | Flip Animation Example in Android

Hello friends!
Today I am going to share Flip Animation  in android, for this I am using ViewFlipper . Hope it will help you.

1-Print Screen:


2-MainActivity.java

package com.example.flipanimationdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ViewFlipper;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Set main.XML as the layout for this Activity
setContentView(R.layout.main);

// Set the listener for Button_Next, a quick and dirty way to create a
// listener
Button buttonNext = (Button) findViewById(R.id.Button_next);
buttonNext.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Get the ViewFlipper from the layout
ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);

// Set an animation from res/anim: I pick push left in
vf.setAnimation(AnimationUtils.loadAnimation(view.getContext(),
R.anim.left_to_right));
vf.showNext();
}
});

// Set the listener for Button_Previous, a quick and dirty way to create
// a listener
Button buttonPrevious = (Button) findViewById(R.id.Button_previous);
buttonPrevious.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Get the ViewFlipper from the layout
ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
// Set an animation from res/anim: I pick push left out
vf.setAnimation(AnimationUtils.loadAnimation(view.getContext(),
R.anim.right_to_left));
vf.showPrevious();
}

});

}
}


3-main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <ViewFlipper
        android:id="@+id/details"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffffff"
            android:gravity="center"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tv_city"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="welcome on first page!"
                android:textSize="26dp"
                android:textStyle="bold" >
            </TextView>

            <Button
                android:id="@+id/Button_next"
                android:layout_width="250px"
                android:layout_height="55px"
                android:text="Next"
                android:textSize="18px" >
            </Button>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#ffffff"
             android:gravity="center"
            android:orientation="vertical" >

             <TextView
                android:id="@+id/tv_city"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="welcome on Second page!"
                android:textSize="26dp"
                android:textStyle="bold" >
            </TextView>
            <Button
                android:id="@+id/Button_previous"
                android:layout_width="250px"
                android:layout_height="55px"
                android:text="Previous"
                android:textSize="18px" >
            </Button>
        </LinearLayout>
    </ViewFlipper>
</LinearLayout>

Important: Create anim folder in res folder and add left_to_right.xml and right_to_left.xml

4-left_to_right.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    <translate
        android:duration="700"
        android:fromXDelta="-100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />
</set>

5right_to_left.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    <translate
        android:duration="700"
        android:fromXDelta="0%"
        android:fromYDelta="0%"
        android:toXDelta="100%"
        android:toYDelta="0%" />
</set>

Thanks!

Wednesday, October 17, 2012

Google Map in Android | Map Integration in android | MD5 and Google map demo

Hello Friends,
    I am going to share code for Google map in android hope it will help you.Important step for Create a Google map view are given below-

1-Generate MD5 Certificate from Google. You can follow below given URL.
http://androidhub4you.blogspot.in/2012/10/md5-certificate-fingerprint-in-android.html

2-Change main.xml with given below code


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <com.google.android.maps.MapView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="0vBPD0kMD00ljs8D_SB3ceBjDWfF5VunFYvebfQ" />

</RelativeLayout>

3-Copy and paste below code in your GoogleMapActivity.java


package com.example.googlemapdemo;

import com.google.android.maps.MapActivity;
import android.os.Bundle;

public class GoogleMapActivity extends MapActivity
{  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}

4-Make changes in manifest.xml file add permission for Internet and add uses Library.


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemapdemo"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:name="com.google.android.maps" />
        <activity
            android:name=".GoogleMapActivity"
            android:label="@string/title_activity_google_map" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Output:



Thanks,








MD5 Certificate Fingerprint in Android


          MD5 Certificate genration is needed for implement google map in our apllication so first we need to genrate md5 certificate.
We can generate it in different opperating systems-

Step1-

Windows Vista: C:\Users\<user>\.android\debug.keystore

Windows XP: C:\Documents and Settings\<user>\.android\debug.keystore

OS X and Linux: ~/.android/debug.keystore

Open console/terminal on to the above location where debug.keystore file is present and execute

"keytool -list -keystore debug.keystore"

Output will be like (press simply enter when password is asked)
=====================================================================
root@ZSS0057:~/.android# keytool -list -keystore debug.keystore
Enter keystore password:
*****************  WARNING WARNING WARNING  *****************
* The integrity of the information stored in your keystore  *
* has NOT been verified!  In order to verify its integrity, *
* you must provide your keystore password.                  *
*****************  WARNING WARNING WARNING  *****************

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

androiddebugkey, 11 Sep, 2012, PrivateKeyEntry,
Certificate fingerprint (MD5): 04:FB:63:04:D5:6B:12:92:9F:3E:20:9F:23:DD:B8:53

Step2-
copy MD5 Certificate fingerprint and paste it in below url-

https://developers.google.com/android/maps-api-signup

You will get Map Keys On successful signup. Put those in the MapView Element of your view.


Thanks,


Sunday, October 14, 2012

Web View In Android | Web View example in Android | Web View demo inside Application in Android | Web View Open Into Application

Hello Friends,
      I am going to share very simple and important code for web-view in android which will open inside the application not on default browser. Please don't forget to add Internet permission in manifest file.

1-Print Screen:

2-WebViewDemoActivity.java
package com.web.demo;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebViewDemoActivity extends Activity {
WebView webView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.yourwebview);
// force web view to open inside application
webView.setWebViewClient(new MyWebViewClient());
openURL();

}

private void openURL() {
webView.loadUrl("http://google.co.in");
}

private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}


3-main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <WebView android:id="@+id/yourwebview"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content" />

</LinearLayout>

4-manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.web.demo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />
   <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".WebViewDemoActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Tuesday, October 9, 2012

Custom Calendar in Android | Android Calendar Example with full source code

Hello dear friends,
 Today I am going to share very Important code for custom calender in Android.
Actually android not provide any calender view so its a very big draw back for developer but we can create a custom calender using grid-view.Important step is given below-
 1- Create new project e.g.-CustomCalenderAndroid
2- Create an activity MyCalendarActivity.java
3- Create layout my_calendar_view.xml
4- Create another xml file screen_gridcell.xml
 5- Add styles_calendar_events.xml in values folder
6- Add Images for calendar in drawable folder


1-Print Screen:



2-MyCalendarActivity.java


package com.examples;

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.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

@TargetApi(3)
public class MyCalendarActivity extends Activity implements OnClickListener {
 private static final String tag = "MyCalendarActivity";

 private TextView currentMonth;
 private Button selectedDayMonthYearButton;
 private ImageView prevMonth;
 private ImageView nextMonth;
 private GridView calendarView;
 private GridCellAdapter adapter;
 private Calendar _calendar;
 @SuppressLint("NewApi")
 private int month, year;
 @SuppressWarnings("unused")
 @SuppressLint({ "NewApi", "NewApi", "NewApi", "NewApi" })
 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.my_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 = (TextView) this.findViewById(R.id.currentMonth);
  currentMonth.setText(DateFormat.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(DateFormat.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 int daysInMonth;
  private int currentDayOfMonth;
  private int currentWeekDay;
  private Button gridcell;
  private TextView num_events_per_day;
  private final HashMap<String, Integer> 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>();
   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);
   int trailingSpaces = 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.");

   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);
   }

   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)))
    if (mm == 2)
     ++daysInMonth;
    else if (mm == 3)
     ++daysInPrevMonth;

   // 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<String, Integer> findNumberOfEventsPerMonth(int year,
    int month) {
   HashMap<String, Integer> map = new HashMap<String, Integer>();

   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.screen_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(getResources()
      .getColor(R.color.lightgray));
   }
   if (day_color[1].equals("WHITE")) {
    gridcell.setTextColor(getResources().getColor(
      R.color.lightgray02));
   }
   if (day_color[1].equals("BLUE")) {
    gridcell.setTextColor(getResources().getColor(R.color.orrange));
   }
   return row;
  }

  @Override
  public void onClick(View view) {
   String date_month_year = (String) view.getTag();
   selectedDayMonthYearButton.setText("Selected: " + date_month_year);
   Log.e("Selected date", 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;
  }
 }
}

3-my_calendar_view.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/lightgray"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/buttonlayout"
        android:layout_width="fill_parent"
        android:layout_height="60sp"
        android:background="@drawable/topbar"
        android:gravity="left|top"
        android:height="60sp"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/settings"
            android:layout_width="54sp"
            android:layout_height="60sp"
            android:background="@drawable/meenu" />

        <ImageView
            android:id="@+id/prevMonth"
            android:layout_width="20sp"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_marginLeft="10sp"
            android:src="@drawable/calendar_left_arrow_selector" >
        </ImageView>

        <TextView
            android:id="@+id/currentMonth"
            android:layout_width="fill_parent"
            android:layout_height="60sp"
            android:layout_weight="0.6"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFFFFF" >
        </TextView>

        <ImageView
            android:id="@+id/nextMonth"
            android:layout_width="20sp"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_marginRight="10sp"
            android:src="@drawable/calendar_right_arrow_selector" >
        </ImageView>

        <Button
            android:id="@+id/addEvent"
            android:layout_width="54sp"
            android:layout_height="60sp"
            android:background="@drawable/plus" />
    </LinearLayout>

    <Button
        android:id="@+id/selectedDayMonthYear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/calendar_top_header"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#FFFFFF" >
    </Button>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center" >

        <ImageView
            android:id="@+id/calendarheader"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/calendar_days" >
        </ImageView>
    </LinearLayout>

    <GridView
        android:id="@+id/calendar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:numColumns="7" >
    </GridView>

</LinearLayout>

4-screen_gridcell.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/calendar_button_selector"
    android:orientation="vertical" >

    <Button
        android:id="@+id/calendar_day_gridcell"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/calendar_button_selector"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#FFFFFF" >
    </Button>

    <TextView
        android:id="@+id/num_events_per_day"
        style="@style/calendar_event_style"
        android:layout_width="10dip"
        android:layout_height="10dip"
        android:layout_gravity="right" >
    </TextView>

</RelativeLayout>


5-ZIP CODE(Download here!)


Hope it will help you...
Thanks...