VOOZH about

URL: https://www.geeksforgeeks.org/android/android-creating-a-calendar-view-app/

⇱ Creating a Calendar View app in Android - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Creating a Calendar View app in Android

Last Updated : 12 Feb, 2025

This article shows how to create an android application for displaying the Calendar using CalendarView. It also provides the selection of the current date and displaying the date. The setOnDateChangeListener Interface is used which provide onSelectedDayChange method.

onSelectedDayChange: In this method, we get the values of days, months, and years that are selected by the user.

Step by Step Implementation

Step 1: Create a new project in Android Studio

Below are the steps to be followed:

  1. Click on File, then New => New Project.
  2. After that include the Kotlin support and click on next.
  3. Select the minimum SDK as per convenience and click next button.
  4. Then select the Empty activity => next => finish.

Step 2: Working with activity_main.xml

Open your xml file and add CalendarView and TextView. And assign id to TextView and CalendarView. After completing this process, the xml file screen looks like given below.

activity_main.xml:

Design UI:

👁 Layout


Step 3: Working with MainActivity.kt

Open up the MainActivity file and define the CalendarView and TextView type variable, and also use findViewById() to get both the views. Add setOnDateChangeListener interface in object of CalendarView which provides setOnDateChangeListener method. In this method, we get the Dates(days, months, years) and set the dates in TextView for Display.

MainActivity File:

Output:

Comment

Explore