How to Create a Custom Calendar App to store reminders and events using SQLite Database in Android Studio?

This page shows the steps to create a Custom Calendar App in which Events and reminders corresponding to a particular date is stored using the SQLite database.

One can also refer to my other video which explains the steps to store the password in encrypted format in your App using the below link:

How to use Facebook Conceal Method to Encrypt your data like password before storing in SQLite Database in Android? – Complete source code

We will be glad to hear from you regarding any query, suggestions or appreciations at: programmerworld1990@gmail.com

Source Code:

package com.example.mycustomcalendar;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CalendarView;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

private mySQLiteDBHandler dbHandler;
private EditText editText;
private CalendarView calendarView;
private String selectedDate;
private SQLiteDatabase sqLiteDatabase;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

editText = findViewById(R.id.editText);
calendarView = findViewById(R.id.calendarView);

calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
selectedDate = Integer.toString(year) + Integer.toString(month) + Integer.toString(dayOfMonth);
ReadDatabase(view);
}
});

try{

dbHandler = new mySQLiteDBHandler(this, “CalendarDatabase”, null,1);
sqLiteDatabase = dbHandler.getWritableDatabase();
sqLiteDatabase.execSQL(“CREATE TABLE EventCalendar(Date TEXT, Event TEXT)”);
}
catch (Exception e){
e.printStackTrace();
}
}

public void InsertDatabase(View view){
ContentValues contentValues = new ContentValues();
contentValues.put(“Date”,selectedDate);
contentValues.put(“Event”, editText.getText().toString());
sqLiteDatabase.insert(“EventCalendar”, null, contentValues);

}

public void ReadDatabase(View view){
String query = “Select Event from EventCalendar where Date = ” + selectedDate;
try{
Cursor cursor = sqLiteDatabase.rawQuery(query, null);
cursor.moveToFirst();
editText.setText(cursor.getString(0));
}
catch (Exception e){
e.printStackTrace();
editText.setText(“”);
}
}

}

package com.example.mycustomcalendar;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.Nullable;

public class mySQLiteDBHandler extends SQLiteOpenHelper {
public mySQLiteDBHandler(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) {

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
package=”com.example.mycustomcalendar”>

<application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round”
android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>

</manifest>

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:app=”http://schemas.android.com/apk/res-auto&#8221;
xmlns:tools=”http://schemas.android.com/tools&#8221;
android:layout_width=”match_parent”
android:layout_height=”match_parent”
tools:context=”.MainActivity”>

<CalendarView
android:id=”@+id/calendarView”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginStart=”25dp”
android:layout_marginTop=”5dp” />

<Button
android:id=”@+id/buttonSave”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginStart=”150dp”
android:layout_marginTop=”320dp”
android:text=”@string/save” />

<EditText
android:id=”@+id/editText”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginStart=”100dp”
android:layout_marginTop=”400dp”
android:ems=”10″
android:inputType=”textPersonName”
android:text=”@string/event_name”
android:autofillHints=”” />
</RelativeLayout>

Top posts/ comments from YouTube channel:

Can anyone tell me how to add update event in this code ?
If I understand you rightly then you want to add an update functionality for your SQLite database. That you can do by using sqLiteDatabase.update API in your java code.
A sample use case of this is also shown in my below video:
(In this video it mainly focuses on showing facebook conceal method to encrypt the data before saving in SQLite database but it shows the update functionality of the database).

2 comments

Leave a Reply

%d bloggers like this: