How to use calendar view inside android application to show a complete calendar with days, months, years, Sunday included.
In this tutorial we are using CalendarView widget, this widget is one of the most special view available for android developer where you can show a complete calendar view with Sunday,Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and also all months calender like real view. So here is the complete step by step tutorial for Android Show CalendarView widget example tutorial with Source code.
Android Show CalendarView widget example tutorial with Source code.
Code for MainActivity.java file.
package com.calendarview_android_examples.com; import android.app.Activity; import android.os.Bundle; import android.widget.CalendarView; import android.widget.TextView; public class MainActivity extends Activity { CalendarView calenderview; TextView displaydata; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); calenderview = (CalendarView)findViewById(R.id.calendarView1); displaydata = (TextView)findViewById(R.id.textView1); calenderview.setOnDateChangeListener(new CalendarView.OnDateChangeListener() { @Override public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) { // TODO Auto-generated method stub displaydata.setText("Date: " + dayOfMonth + "/" + (month+1) + "/" + year); } }); } }
Code for activity_main.xml layout file.
<RelativeLayout 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" 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.calendarview_android_examples.com.MainActivity" > <CalendarView android:id="@+id/calendarView1" android:layout_width="fill_parent" android:layout_height="300dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/calendarView1" android:layout_centerHorizontal="true" android:layout_marginBottom="28dp" android:text="Date Display here" android:textAppearance="?android:attr/textAppearanceLarge" /> </RelativeLayout>
Screenshot: