This example shows how you can create calendar view in android.
NOTE: Minimum API level must be 11.
1.) Create a new project by File-> New -> Android Project name it CalenderViewExample.
2.) Write following into main.xml:
<LinearLayout 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" android:orientation="vertical" tools:context=".CalenderViewExampleActivity" > <CalendarView android:id="@+id/calendar" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
3.) Run for output.
1.) Create a project named CalenderViewExample and set the information as stated in the image.
Build Target: Android 4.3
Application Name: CalenderViewExample
Package Name: com.example. CalenderViewExample
Activity Name: CalenderViewExampleActivity
2.) Open CalenderViewExampleActivity.java file and write following code there:
package com.example.calenderviewexample; import android.os.Bundle; import android.widget.CalendarView; import android.widget.CalendarView.OnDateChangeListener; import android.widget.Toast; import android.app.Activity; public class CalenderViewExampleActivity extends Activity { CalendarView calendar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); calendar = (CalendarView)findViewById(R.id.calendar); calendar.setOnDateChangeListener(new OnDateChangeListener(){ @Override public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) { Toast.makeText(getApplicationContext(), dayOfMonth +"/"+month+"/"+ year,Toast.LENGTH_LONG).show();}}); } }
3.) Compile and build the project.
Output
Top 10 Android App Development Trends | 2020 Guide
5 Best Resources to Get Started with Android Nougat
Android Studio Introduction
Services – An Android Component
Applying MediaCodec On An Open Source Android Audio Player
5 Most Used Android Testing Frameworks
Android Language Highlights A Developers Perspective
Android KitKat Development