CalenderView Example

Hi Guys,

Today I am sharing the code for CalenderView. This class is a calendar widget for displaying and selecting dates. The range of dates supported by this calendar is configurable. A user can select a date by taping on it and can scroll and fling the calendar to a desired date.

activity_main.xml

<Relativelayout android:layout_height="match_parent" android:layout_width="match_parent" 
android:paddingbottom="@dimen/activity_vertical_margin"
 android:paddingleft="@dimen/activity_horizontal_margin" 
android:paddingright="@dimen/activity_horizontal_margin" 
android:paddingtop="@dimen/activity_vertical_margin"
 tools:context="com.sunil.calenderexample.MainActivity" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools">

   <Calendarview 
android:id="@+id/calendarView_cl"
android:layout_alignparentleft="true" 
android:layout_alignparenttop="true" 
android:layout_height="match_parent" 
android:layout_width="match_parent"/>

</Relativelayout>

MainActivity.java

package com.sunil.calenderexample;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CalendarView;
import android.widget.CalendarView.OnDateChangeListener;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity implements OnDateChangeListener {

 private CalendarView calenderview=null;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  calenderview=(CalendarView)findViewById(R.id.calendarView_cl);
  calenderview.setOnDateChangeListener(this);
  
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  if (id == R.id.action_settings) {
   return true;
  }
  return super.onOptionsItemSelected(item);
 }

 @Override
 public void onSelectedDayChange(CalendarView arg0, int arg1, int arg2, int arg3) {
  
  Toast.makeText(getBaseContext(), arg1+"/"+arg2+"/"+arg3, Toast.LENGTH_LONG).show();
 }
}


Result is:
Here you can download the source code CalenderView Example

11 comments:

  1. good example
    http://appsdevelopment-for-mobiles.blogspot.com/

    ReplyDelete
  2. Very nice post , thanks for sharing this post with us and gave us a good information regarding this. I really like it.

    ReplyDelete
  3. Android Tutorial for Beginners learns android programming and how to develop android mobile phone and ipad applications starting from environment setup.

    ReplyDelete
  4. Android Pro apps
    http://checkingtricks.blogspot.com/2014/10/android-smart-memory-booster-pro.html#axzz3GDnUmQIO

    ReplyDelete
  5. Hey thanks for sharing the example view of a calendar programming! you can also visit my website to check out some more cool applications!

    ReplyDelete

Debug Database in Android

In my last tutorial, we have learned how we can use persistence database in android. We also understood which database wrapper we can use...

Contact Me

Name

Email *

Message *