Create Calendar Android Application

Introduction

 
Android is one of the most popular operating systems for mobiles. In this article, I will show you how to create a Calendar Android application. The calendar is an important thing to handle events and commitments. So, I will show you how to create a calendar in Android applications using Android Studio.
 
Requirements
Steps should be followed
 
Follow these steps to create a Native Calendar Android application using Android Studio. I have attached the source code too.
 
Step 1
 
Open Android Studio and start a New Android Studio Project.
 
Android
 
Step 2
 
You can choose your application name and choose where your project is stored. If you wish to use C++ for coding the project, mark the "Include C++ support", and click the "Next" button.
 
Android
 
Now, select the version of Android and select the target Android devices.
 
Android
 
Step 3
 
Now, add the activity and click the "Next" button.
 
Android
 
Add activity name and click "Finish".
 
Android
 
Step 4
 
Go to activity_main.xml, This XML file contains the designing code for an Android app.
 
Android
 
The XML code is given below.
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  4.     xmlns:tools="http://schemas.android.com/tools"  
  5.     android:layout_width="match_parent"  
  6.     android:layout_height="match_parent"  
  7.     tools:context="abu.calendar.MainActivity">  
  8.   
  9.     <TextView  
  10.         android:id="@+id/date"  
  11.         android:layout_width="0dp"  
  12.         android:layout_height="51dp"  
  13.         android:text="Date"  
  14.         android:textAlignment="center"  
  15.         android:textSize="45dp"  
  16.         android:visibility="visible"  
  17.         app:layout_constraintBottom_toBottomOf="parent"  
  18.         app:layout_constraintHorizontal_bias="0.0"  
  19.         app:layout_constraintLeft_toLeftOf="parent"  
  20.         app:layout_constraintRight_toRightOf="parent"  
  21.         app:layout_constraintTop_toTopOf="parent"  
  22.   
  23.   
  24.         app:layout_constraintVertical_bias="0.219" />  
  25.   
  26.     <Button  
  27.         android:id="@+id/btngocalendar"  
  28.         android:layout_width="266dp"  
  29.         android:layout_height="47dp"  
  30.         android:text=" Calendar"  
  31.         tools:layout_editor_absoluteX="47dp"  
  32.         tools:layout_editor_absoluteY="8dp" />  
  33.   
  34. </android.support.constraint.ConstraintLayout> 
Step 5
 
Go to layout ⇒ New ⇒XML⇒Layout XML file.
 
Android
 
The layout XML code is given below.
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical" android:layout_width="match_parent"  
  4.     android:layout_height="match_parent">  
  5.   
  6.     <CalendarView  
  7.         android:id="@+id/calendarView"  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="wrap_content" />  
  10. </LinearLayout>  
Step 6
 
Go to  Java ⇒ New ⇒Java class.
 
Android
 
The calendar activity java code is given below.
  1. package abu.calendar;  
  2.   
  3. import android.content.Intent;  
  4. import android.os.Bundle;  
  5. import android.support.annotation.Nullable;  
  6. import android.support.v7.app.AppCompatActivity;  
  7. import android.util.Log;  
  8. import android.widget.CalendarView;  
  9.   
  10. public class calendaractivity extends AppCompatActivity {  
  11.   
  12.     private  static final String TAG = "CalendarActivity";  
  13.     private CalendarView mCalendarView;  
  14.     @Override  
  15.     protected void onCreate(@Nullable Bundle savedInstanceState) {  
  16.         super.onCreate(savedInstanceState);  
  17.         setContentView(R.layout.calendar_layout);  
  18.         mCalendarView = (CalendarView) findViewById(R.id.calendarView);  
  19.         mCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {  
  20.             @Override  
  21.             public void onSelectedDayChange(CalendarView CalendarView, int year, int month, int dayOfMonth) {  
  22.                 String date = year + "/" + month + "/"+ dayOfMonth ;  
  23.                 Log.d(TAG, "onSelectedDayChange: yyyy/mm/dd:" + date);  
  24.                 Intent intent = new Intent(calendaractivity.this,MainActivity.class);  
  25.                 intent.putExtra("date",date);  
  26.                 startActivity(intent);  
  27.   
  28.             }  
  29.         });  
  30.     }  
  31.   
  32. }                                           
Step 7
 
Go to  Main Activity.java. This Java program is the back-end language for Android. The Java code is given below.
  1. package abu.calendar;  
  2.   
  3. import android.content.Intent;  
  4. import android.os.Bundle;  
  5. import android.support.v7.app.AppCompatActivity;  
  6. import android.view.View;  
  7. import android.widget.Button;  
  8. import android.widget.TextView;  
  9.   
  10. public class MainActivity extends AppCompatActivity {  
  11.   
  12.     private static final String TAG = "MainActivity";  
  13.   
  14.     private TextView thedate;  
  15.     private Button btngocalendar;  
  16.   
  17.     @Override  
  18.     protected void onCreate(Bundle savedInstanceState) {  
  19.         super.onCreate(savedInstanceState);  
  20.         setContentView(R.layout.activity_main);  
  21.         thedate = (TextView) findViewById(R.id.date);  
  22.         btngocalendar = (Button) findViewById(R.id.btngocalendar);  
  23.   
  24.         Intent incoming = getIntent();  
  25.         String date = incoming.getStringExtra("date");  
  26.         thedate.setText(date);  
  27.   
  28.         btngocalendar.setOnClickListener(new View.OnClickListener() {  
  29.             @Override  
  30.             public void onClick(View v) {  
  31.                 Intent intent = new Intent(MainActivity.this,calendaractivity.class);  
  32.                 startActivity(intent);  
  33.             }  
  34.         });  
  35.     }  
  36. }  
Step 8
 
We need to make Calendar View. So, add calendaractivity in an AndroidManifest.xml.
 
Android
 
The AndroidManifest.xml Code is this,
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="abu.calendar">  
  4.   
  5.     <application  
  6.         android:allowBackup="true"  
  7.         android:icon="@mipmap/ic_launcher"  
  8.         android:label="@string/app_name"  
  9.         android:roundIcon="@mipmap/ic_launcher_round"  
  10.         android:supportsRtl="true"  
  11.         android:theme="@style/AppTheme">  
  12.         <activity android:name=".MainActivity">  
  13.             <intent-filter>  
  14.                 <action android:name="android.intent.action.MAIN" />  
  15.   
  16.                 <category android:name="android.intent.category.LAUNCHER" />  
  17.             </intent-filter>  
  18.         </activity>  
  19.         <activity android:name=".calendaractivity"></activity>  
  20.     </application>  
  21.   
  22.   
  23. </manifest>  
Step 9
 
Now, either go to the menu bar and click "Make a project" or press ctrl+f9 to debug the error.
 
Android
 
Step 10
 
Then, click the "Run" button or press shift+f10 to run the project. Select the "virtual machine" option and click OK.
 
Android
 

Conclusion

 
We have successfully created a Calendar Android application using Android Studio.
 
Android
 
Android