{"id":87541,"date":"2023-05-15T10:11:51","date_gmt":"2023-05-15T04:41:51","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=87541"},"modified":"2023-05-15T10:11:51","modified_gmt":"2023-05-15T04:41:51","slug":"android-to-do-list-app","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/","title":{"rendered":"Android Kotlin Project &#8211; To Do List App"},"content":{"rendered":"<p>Hey there Android enthusiasts, today we are going to see and learn to implement an Android Project that is a To-do List App in android studio. We\u2019ll understand the complete project development in this article.<\/p>\n<p>The Todo List App will come in handy for keeping track of the tasks we want to complete in the future. With the assistance of this application, you can add new tasks you need to complete and choose whether to check them off after they&#8217;re finished. Users using to-do list apps can be more productive, experience less worry and stress, and feel a sense of success when they finish their tasks.<\/p>\n<h3>About Android To Do List App<\/h3>\n<p>This is an Android project for those just learning the fundamentals of developing Android applications. This Android app&#8217;s user interface has a floating button in the bottom right corner of the home page that allows users to add new tasks.<\/p>\n<p>The home screen will display all the tasks entered by the user.<\/p>\n<p>We will use Android Studio and the programming language Kotlin to develop this Android application. Let&#8217;s look over the list of features that the user interface will include:<\/p>\n<p>1. The user interface will have a floating \u2018+\u2019 button at the right bottom corner of the home screen.<br \/>\n2. A bottom screen fragment will come up when the \u2018+\u2019 button is clicked which contains two text fields.<br \/>\n3. In the two text fields, the task name and description can be added by the user.<br \/>\n4. The \u2018Save\u2019 button at the bottom of the sheet fragment will save the newly entered task details onto the ROOM database and display it on the home screen.<br \/>\nAll of the tasks that the user has entered will be listed on the home screen, along with a checkbox that can be used to mark a task as complete.<\/p>\n<h3>Prerequisites for To Do List App using Android<\/h3>\n<p>To develop this Android application the requirements and prerequisites are as follows:<\/p>\n<p><strong>1. Kotlin:<\/strong> You need first be familiar with Kotlin programming. Given that we will write the app code in the programming language Kotlin, it is necessary.<\/p>\n<p><strong>2. XML:<\/strong> Another crucial component of our Android application is XML. It will be applied to the development of the application&#8217;s user interface.<\/p>\n<p><strong>3. Android Studio:<\/strong> The core of our application is Android Studio because that is how we will develop it. Also included with Android Studio is an Android virtual device that can be used to test the functionality of applications.<\/p>\n<p><strong>4. ROOM DAOs:<\/strong> These refer to the queries that will be required to insert\/write the data into the database. Basic database management knowledge is important.<\/p>\n<h3>Download Android To Do List App Project<\/h3>\n<p>Please download the source code of Android To Do List App Project from the following link: <a href=\"https:\/\/techvidvan.s3.amazonaws.com\/android-projects\/kotlin\/ToDoTechVidvan.zip\"><strong>Android To Do List App Project Code<\/strong><\/a><\/p>\n<h3>Steps to Create To Do List Project using Android<\/h3>\n<p>Following are the steps for developing the Android To Do List Project:<\/p>\n<p>Let&#8217;s begin by developing the to-do list app in Android Studio. For a better understanding of how the app works, step-by-step instructions have been provided for each and every file in this tutorial.<\/p>\n<p>You must complete a set of steps in order to create this Android todo-list application.<\/p>\n<p>1. Extract all the files from the downloaded zip file to the location of your choice.<br \/>\n2. Open Android Studio.<br \/>\n3. Click on File then Open.<br \/>\n4. Find and select the folder you extracted earlier and click on OK.<\/p>\n<p>You have successfully opened the todo-list app\u2019s source code in android studio.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/android-studio-1.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87699 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/android-studio-1.webp\" alt=\"android studio\" width=\"1918\" height=\"996\" \/><\/a><\/p>\n<p>Let&#8217;s go through each file in this project one at a time as we comprehend how the application works.<\/p>\n<p>1. The \u201cactivity_main\u201d is a XML file which is responsible for creating the text fields and buttons included in the user interface.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;RelativeLayout\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    tools:context=\".MainActivity\"&gt;\n\n    &lt;androidx.recyclerview.widget.RecyclerView\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:id=\"@+id\/todoListRecyclerView\"\n        android:backgroundTint=\"@color\/design_default_color_background\"\n        \/&gt;\n\n    &lt;com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"Add Task\"\n        android:id=\"@+id\/newTaskButton\"\n        android:backgroundTint=\"?attr\/colorPrimary\"\n        android:textColor=\"?colorOnPrimary\"\n        android:layout_alignParentBottom=\"true\"\n        android:layout_alignParentEnd=\"true\"\n        android:padding=\"5dp\"\n        android:layout_margin=\"20dp\"\n        app:iconTint=\"?colorOnPrimary\"\n        app:icon=\"@drawable\/ic_baseline_add_24\"\n        \/&gt;\n\n\n&lt;\/RelativeLayout&gt;<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/activity-mainxml.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87700 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/activity-mainxml.webp\" alt=\"activity main(xml)\" width=\"1920\" height=\"1002\" \/><\/a><\/p>\n<p>2. The \u201cfragment_new_task_sheet\u201d is a XML file which is responsible for creating the edit text views for the user to enter new task\u2019s name and description along with the save button. This xml file will appear when the user click on the \u2018Add Task\u2019 in the main activity.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    tools:context=\".NewTaskSheet\"\n    android:orientation=\"vertical\"&gt;\n\n    &lt;TextView\n        android:id=\"@+id\/taskTitle\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"New Task\"\n        android:textSize=\"30sp\"\n        android:layout_marginTop=\"20dp\"\n        android:layout_marginStart=\"20dp\"\n        style=\"@style\/TextAppearance.AppCompat.Title\"\/&gt;\n\n\n    &lt;com.google.android.material.textfield.TextInputLayout\n        style=\"@style\/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginVertical=\"10dp\"\n        android:layout_marginHorizontal=\"20dp\"&gt;\n\n        &lt;com.google.android.material.textfield.TextInputEditText\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\"\n            android:id=\"@+id\/name\"\n            android:hint=\"Name\"\/&gt;\n\n    &lt;\/com.google.android.material.textfield.TextInputLayout&gt;\n\n    &lt;com.google.android.material.textfield.TextInputLayout\n        style=\"@style\/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_marginVertical=\"10dp\"\n        android:layout_marginHorizontal=\"20dp\"&gt;\n\n        &lt;com.google.android.material.textfield.TextInputEditText\n            android:layout_width=\"match_parent\"\n            android:layout_height=\"match_parent\"\n            android:id=\"@+id\/desc\"\n            android:hint=\"Description\"&gt;\n\n        &lt;\/com.google.android.material.textfield.TextInputEditText&gt;\n\n    &lt;\/com.google.android.material.textfield.TextInputLayout&gt;\n\n    &lt;com.google.android.material.button.MaterialButton\n        android:id=\"@+id\/saveButton\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:layout_gravity=\"center\"\n        android:layout_marginHorizontal=\"20dp\"\n        android:text=\"Save\"\/&gt;\n\n&lt;\/LinearLayout&gt;<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/fragment-new-task-sheetxml.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87701 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/fragment-new-task-sheetxml.webp\" alt=\"fragment new task sheet(xml)\" width=\"1920\" height=\"996\" \/><\/a><\/p>\n<p>3. \u2018Task_item_cell\u2019 is a XML file which is responsible for creating the user interface (UI) for tasks that are presented on the home screen.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;androidx.cardview.widget.CardView android:id=\"@+id\/taskCellContainer\"\n    app:cardCornerRadius=\"5dp\"\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"90dp\"\n    android:layout_margin=\"5dp\"\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"&gt;\n\n    &lt;LinearLayout\n        android:orientation=\"horizontal\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"&gt;\n\n        &lt;ImageButton\n            android:layout_width=\"wrap_content\"\n            android:layout_height=\"wrap_content\"\n            android:layout_gravity=\"center\"\n            android:scaleY=\"1.5\"\n            android:scaleX=\"1.5\"\n            android:contentDescription=\"@string\/checkbox\"\n            android:id=\"@+id\/completeButton\"\n            android:layout_marginHorizontal=\"15dp\"\n            android:src=\"@drawable\/unchecked_24\"\n            android:backgroundTint=\"@android:color\/transparent\"\n            \/&gt;\n\n        &lt;TextView\n            android:layout_width=\"0dp\"\n            android:layout_height=\"wrap_content\"\n            android:id=\"@+id\/name\"\n            android:text=\"@string\/place_holder\"\n            style=\"@style\/TextAppearance.AppCompat.Title\"\n            android:layout_gravity=\"center\"\n            android:layout_weight=\"1\"\n            \/&gt;\n    &lt;\/LinearLayout&gt;\n&lt;\/androidx.cardview.widget.CardView&gt;<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-item-cellxml.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87702 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-item-cellxml.webp\" alt=\"task item cell(xml)\" width=\"1920\" height=\"996\" \/><\/a><\/p>\n<p>Let\u2019s start with setting up the necessary files required for creating a ROOM database that will store the task\u2019s name and description.<\/p>\n<p>1. \u2018TaskItem.kt\u2019 is an entity file for the ROOM database that will be created when database is initialized. With the help of this file, respective table and columns will be created in the database.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import android.content.Context\nimport androidx.core.content.ContextCompat\nimport androidx.room.ColumnInfo\nimport androidx.room.Entity\nimport androidx.room.PrimaryKey\nimport java.time.LocalDate\nimport java.time.format.DateTimeFormatter\n\n\n@Entity(tableName = \"task_item_table\")\nclass TaskItem(\n    @ColumnInfo(name = \"name\")var name: String,\n    @ColumnInfo(name= \"desc\")var desc: String,\n    @ColumnInfo(name = \"completedDateString\")var completedDateString: String?,\n    @PrimaryKey(autoGenerate = true)var id: Int = 0\n) {\n    fun completedDate(): LocalDate? = if (completedDateString == null) null else LocalDate.parse(completedDateString, dateFormatter)\n    fun isCompleted() = completedDate() != null\n    fun imageResource(): Int = if(isCompleted()) R.drawable.checked_24 else R.drawable.unchecked_24\n    fun imageColor(context: Context): Int = if(isCompleted()) purple(context) else black(context)\n\n    private fun purple(context: Context) = ContextCompat.getColor(context, R.color.purple_500)\n    private fun black(context: Context) = ContextCompat.getColor(context, R.color.black)\n\n    companion object{\n        val dateFormatter: DateTimeFormatter = DateTimeFormatter.ISO_DATE\n    }\n}<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-itemkt.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87703 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-itemkt.webp\" alt=\"task item(kt)\" width=\"1920\" height=\"996\" \/><\/a><\/p>\n<p>2. \u2018TaskItemDAO.kt\u2019 is an interface which is a data access object responsible for defining the methods that can access the database. Using annotations, we have defined \u2018insert\u2019 query in this file which will insert the data in the specified database table, \u2018update\u2019 which enables the user to update a task already stored in the database.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import androidx.room.*\nimport kotlinx.coroutines.flow.Flow\n\n\n@Dao\ninterface TaskItemDao {\n    @Query(\"SELECT * FROM task_item_table ORDER BY id ASC\")\n    fun allTaskItems(): Flow&lt;List&lt;TaskItem&gt;&gt;\n\n    @Insert(onConflict = OnConflictStrategy.REPLACE)\n    suspend fun insertTaskItem(taskItem: TaskItem)\n\n    @Update\n    suspend fun updateTaskItem(taskItem: TaskItem)\n}<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-item-daokt.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87704 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-item-daokt.webp\" alt=\"task item dao(kt)\" width=\"1920\" height=\"1003\" \/><\/a><\/p>\n<p>3. \u2018AppDatabase.kt\u2019 is an abstract class file which is responsible to initialize the database. In this file, the code makes sure that only one instance of the database is created even if it is a triggered multiple time.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import android.content.Context\nimport androidx.room.Database\nimport androidx.room.Room\nimport androidx.room.RoomDatabase\n@Database(entities = [TaskItem::class], version = 1, exportSchema = false)\npublic abstract class TaskItemDatabase : RoomDatabase()\n{\n    abstract fun taskItemDao(): TaskItemDao\n\n    companion object\n    {\n        @Volatile\n        private var INSTANCE: TaskItemDatabase? = null\n        fun getDatabase(context: Context): TaskItemDatabase\n        {\n            return INSTANCE ?: synchronized(this)\n            {\n                val instance = Room.databaseBuilder(\n       \t\t    context.applicationContext,\n                    TaskItemDatabase::class.java,\n                    \"task_item_database\"\n                ).build()\n                INSTANCE = instance\n                instance\n            }\n        }\n    }\n}<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-item-databasekt.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87705 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-item-databasekt.webp\" alt=\"task item database(kt)\" width=\"1920\" height=\"996\" \/><\/a><\/p>\n<p>Moving onto the files that are responsible for the working and functioning of the application.<\/p>\n<p>1. \u201cMainActivity\u201d is a kotlin file which is responsible to initialize our application.<br \/>\nThis file contains various functions that are responsible for the working and functioning of our application.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import androidx.appcompat.app.AppCompatActivity\nimport android.os.Bundle\nimport androidx.activity.viewModels\nimport androidx.recyclerview.widget.LinearLayoutManager\nimport com.example.todo_techvidvan.databinding.ActivityMainBinding\n\nclass MainActivity : AppCompatActivity(), TaskItemListener {\n    private lateinit var binding: ActivityMainBinding\n    private val taskViewModel: TaskViewModel by viewModels {\n        TaskItemModelFactory((application as TodoApplication).repository)\n    }\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        binding = ActivityMainBinding.inflate(layoutInflater)\n        setContentView(binding.root)\n        binding.newTaskButton.setOnClickListener {\n            NewTaskSheet(null).show(supportFragmentManager, \"newTaskTag\")\n        }\n        setRecyclerView()\n    }\n\n    private fun setRecyclerView() {\n        val mainActivity = this\n        taskViewModel.taskItems.observe(this){\n            binding.todoListRecyclerView.apply {\n                layoutManager = LinearLayoutManager(applicationContext)\n                adapter = TaskItemAdapter(it, mainActivity)\n            }\n        }\n    }\n\n    override fun editTaskItem(taskItem: TaskItem) {\n        NewTaskSheet(taskItem).show(supportFragmentManager,\"newTaskTag\")\n    }\n\n    override fun completeTaskItem(taskItem: TaskItem) {\n        taskViewModel.setCompleted(taskItem)\n    }\n}<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/main-activitykt-1.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87706 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/main-activitykt-1.webp\" alt=\"main activity(kt)\" width=\"1920\" height=\"996\" \/><\/a><\/p>\n<p>2. \u2018NewTaskSheet\u2019 is a kotlin file which initializes the fragment which allows the user to add new tasks.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import android.os.Bundle\nimport android.text.Editable\nimport android.view.LayoutInflater\nimport android.view.View\nimport android.view.ViewGroup\nimport androidx.lifecycle.ViewModelProvider\nimport com.example.todo_techvidvan.databinding.FragmentNewTaskSheetBinding\nimport com.google.android.material.bottomsheet.BottomSheetDialogFragment\n\nclass NewTaskSheet(var taskItem: TaskItem?) : BottomSheetDialogFragment() {\n\n    private lateinit var binding: FragmentNewTaskSheetBinding\n    private lateinit var taskViewModel: TaskViewModel\n\n    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {\n        super.onViewCreated(view, savedInstanceState)\n        val activity = requireActivity()\n\n        if(taskItem!=null){\n            binding.taskTitle.text = \"Edit Task\"\n            val editable = Editable.Factory.getInstance()\n            binding.name.text = editable.newEditable(taskItem!!.name)\n            binding.desc.text = editable.newEditable(taskItem!!.desc)\n        }else{\n            binding.taskTitle.text = \"New Task\"\n        }\n        taskViewModel = ViewModelProvider(activity).get(TaskViewModel::class.java)\n        binding.saveButton.setOnClickListener{\n            savAction()\n        }\n    }\n\n    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {\n        binding = FragmentNewTaskSheetBinding.inflate(inflater,container,false)\n        return binding.root\n    }\n\n\n    private fun savAction() {\n       val name = binding.name.text.toString()\n       val desc = binding.desc.text.toString()\n        if(taskItem==null){\n            val newTask = TaskItem(name,desc,null)\n            taskViewModel.addTaskItem(newTask)\n        }else{\n            taskItem!!.name = name\n            taskItem!!.desc = desc\n            taskViewModel.updateTaskItem(taskItem!!)\n        }\n        binding.name.setText(\"\")\n        binding.desc.setText(\"\")\n        dismiss()\n    }\n}<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/new-task-sheetkt.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87707 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/new-task-sheetkt.webp\" alt=\"new task sheet(kt)\" width=\"1920\" height=\"1002\" \/><\/a><\/p>\n<p>3. \u2018TaskItemAdapter.kt\u2019 is a class which contains some important functions to work with the RecyclerView, they are mentioned as follows:<\/p>\n<ul>\n<li>onCreateViewHolder(): This function sets the views to display the items.<\/li>\n<li>onBindViewHolder(): This function is used to bind the list items to our widgets such as TextView, ImageView, etc.<\/li>\n<li>getItemCount(): It returns the count of items present in the list.<\/li>\n<\/ul>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import android.view.LayoutInflater\nimport android.view.ViewGroup\nimport androidx.recyclerview.widget.RecyclerView\nimport com.example.todo_techvidvan.databinding.TaskItemCellBinding\n\nclass TaskItemAdapter(\n    private val taskItems: List&lt;TaskItem&gt;,\n    private val clickListener: TaskItemListener\n): RecyclerView.Adapter&lt;TaskItemViewHolder&gt;() {\n    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TaskItemViewHolder {\n        val from = LayoutInflater.from(parent.context)\n        val binding = TaskItemCellBinding.inflate(from, parent, false)\n        return TaskItemViewHolder(parent.context, binding, clickListener)\n    }\n\n    override fun onBindViewHolder(holder: TaskItemViewHolder, position: Int) {\n        holder.bindTaskItem(taskItems[position])\n    }\n\n    override fun getItemCount(): Int = taskItems.size\n}<\/pre>\n<p>4. \u2018TaskItemRepository.kt\u2019 is a kotlin class which contains worker threads to insert and update the items in the database.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import androidx.annotation.WorkerThread\nimport kotlinx.coroutines.flow.Flow\n\nclass TaskItemRepository(private val taskItemDao: TaskItemDao) {\n    val allTaskItems: Flow&lt;List&lt;TaskItem&gt;&gt; = taskItemDao.allTaskItems()\n    @WorkerThread\n    suspend fun insertTaskItem(taskItem: TaskItem)\n    {\n        taskItemDao.insertTaskItem(taskItem)\n    }\n\n    @WorkerThread\n    suspend fun updateTaskItem(taskItem: TaskItem)\n    {\n        taskItemDao.updateTaskItem(taskItem)\n    }\n}<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-item-repositorykt.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87708 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-item-repositorykt.webp\" alt=\"task item repository(kt)\" width=\"1920\" height=\"1002\" \/><\/a><\/p>\n<p>5. \u2018TaskItemViewHolder.kt\u2019 is a kotlin class which overlooks when a task is completed or being edited and performs the functions defined inside it accordingly.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import android.content.Context\nimport android.graphics.Paint\nimport androidx.recyclerview.widget.RecyclerView\nimport com.example.todo_techvidvan.databinding.TaskItemCellBinding\n\n\nclass TaskItemViewHolder(\n    private val context: Context,\n    private val binding: TaskItemCellBinding,\n    private val clickListener: TaskItemListener\n): RecyclerView.ViewHolder(binding.root) {\n    fun bindTaskItem(taskItem: TaskItem)\n    {\n        binding.name.text = taskItem.name\n\n        if(taskItem.isCompleted()){\n            binding.name.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG\n        }\n\n        binding.completeButton.setImageResource(taskItem.imageResource())\n        binding.completeButton.setColorFilter(taskItem.imageColor(context))\n\n        binding.completeButton.setOnClickListener {\n            clickListener.completeTaskItem(taskItem)\n        }\n\n        binding.taskCellContainer.setOnClickListener{\n            clickListener.editTaskItem(taskItem)\n        }\n    }\n}<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-item-view-holder.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87709 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/task-item-view-holder.webp\" alt=\"task item view holder\" width=\"1920\" height=\"996\" \/><\/a><\/p>\n<p>6. \u2018TodoApplication.kt\u2019 is a kotlin file which initializes the instance of the database when the app is launched.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import android.app.Application\n\nclass TodoApplication:Application() {\n    private val database by lazy { TaskItemDatabase.getDatabase(this) }\n    val repository by lazy { TaskItemRepository(database.taskItemDao()) }\n}<\/pre>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/todo-applicationkt.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87710 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/todo-applicationkt.webp\" alt=\"todo application(kt)\" width=\"1920\" height=\"1002\" \/><\/a><\/p>\n<h3>Android Todo-List App Output<\/h3>\n<p>1. Home Screen<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/android-to-do-list-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87692 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/android-to-do-list-output.webp\" alt=\"android to do list output\" width=\"400\" height=\"867\" \/><\/a><\/p>\n<p>2. New Task sheet fragment when the \u2018add task\u2019 button clicked.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/android-to-do-list-project-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87693 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/android-to-do-list-project-output.webp\" alt=\"android to do list project output\" width=\"400\" height=\"828\" \/><\/a><\/p>\n<p>3. New entered task displayed on the home screen<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/to-do-list-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87694 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/to-do-list-output.webp\" alt=\"to do list output\" width=\"400\" height=\"833\" \/><\/a><\/p>\n<p>4. Updating\/Editing a task by clicking on it.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/android-to-do-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87695 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/android-to-do-output.webp\" alt=\"android to do output\" width=\"400\" height=\"867\" \/><\/a><\/p>\n<p>5. Updated\/Edited Task.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/to-do-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87696 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/to-do-output.webp\" alt=\"to do output\" width=\"400\" height=\"867\" \/><\/a><\/p>\n<p>6. Ticking off tasks that have been finished.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/to-do-list-project-output.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-87697 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/04\/to-do-list-project-output.webp\" alt=\"to do list project output\" width=\"400\" height=\"837\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>So in this project, we have learned how to create and develop a todo list app in android studio. This project is highly beneficial for beginners since it familiarizes users with utilizing XML to create user interfaces, switching between activities by clicking a button, using ROOM database, especially when inserting data into the database, getting familiar with recycler view and its working. We sincerely hope you enjoyed it, and we are sure you will enjoy implementing it into reality.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey there Android enthusiasts, today we are going to see and learn to implement an Android Project that is a To-do List App in android studio. We\u2019ll understand the complete project development in this&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":87689,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4955],"tags":[4910,3007,3010,4979,4980,4981,4982,4983],"class_list":["post-87541","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android-kotlin-tutorials","tag-android-project-for-practice","tag-android-project-ideas","tag-android-projects","tag-android-to-do-list-app","tag-android-to-do-list-app-project","tag-to-do-list-app","tag-to-do-list-app-project","tag-to-do-list-project"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android Kotlin Project - To Do List App - TechVidvan<\/title>\n<meta name=\"description\" content=\"Get organized with our Android To-Do List app! Easily manage tasks, set reminders, and boost productivity on-the-go.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Kotlin Project - To Do List App - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Get organized with our Android To-Do List app! Easily manage tasks, set reminders, and boost productivity on-the-go.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-15T04:41:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/android-to-do-list.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Kotlin Project - To Do List App - TechVidvan","description":"Get organized with our Android To-Do List app! Easily manage tasks, set reminders, and boost productivity on-the-go.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/","og_locale":"en_US","og_type":"article","og_title":"Android Kotlin Project - To Do List App - TechVidvan","og_description":"Get organized with our Android To-Do List app! Easily manage tasks, set reminders, and boost productivity on-the-go.","og_url":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2023-05-15T04:41:51+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/android-to-do-list.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Android Kotlin Project &#8211; To Do List App","datePublished":"2023-05-15T04:41:51+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/"},"wordCount":1170,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/android-to-do-list.webp","keywords":["android project for practice","android project ideas","android projects","android to do list app","android to do list app project","to do list app","to do list app project","to do list project"],"articleSection":["Android Kotlin Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/","url":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/","name":"Android Kotlin Project - To Do List App - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/android-to-do-list.webp","datePublished":"2023-05-15T04:41:51+00:00","description":"Get organized with our Android To-Do List app! Easily manage tasks, set reminders, and boost productivity on-the-go.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/android-to-do-list.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2023\/04\/android-to-do-list.webp","width":1200,"height":628,"caption":"android to do list"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/android-to-do-list-app\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Android Kotlin Project &#8211; To Do List App"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/87541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=87541"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/87541\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/87689"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=87541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=87541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=87541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}