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:
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”
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”
xmlns:app=”http://schemas.android.com/apk/res-auto”
xmlns:tools=”http://schemas.android.com/tools”
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:
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).
sir which package you import in gradle file please send me gradle file also of this app.
I don’t think I have the gradle file of this project. All the codes and details are shared on this page and video.
Cheers
Programmer World
–