Defining a Model

If we are going to show to-do items in this list, it would help to have some to-do items. That, in turn, means that we need a Kotlin class that represents a to-do item. Such a class is often referred to as a “model” class, so in this chapter, we will create a ToDoModel, where each ToDoModel instance represents one to-do item.

This is a continuation of the work we did in the previous tutorial. The book’s GitLab repository contains the results of the previous tutorial as well as the results of completing the work in this tutorial.

Step #1: Adding a Stub POJO

First, let’s create the base ToDoModel class. To do this, right-click over the com.commonsware.todo package in the project tree in Android Studio, and choose “New” > “Kotlin File/Class” from the context menu. As before, this brings up a dialog where we can define a new Kotlin class, by default into the same Java package that we right-clicked over. Fill in ToDoModel in the “Name” field and choose “Class” in the list of available Kotlin structures. Then press Enter or Return to create this class. ToDoModel should show up in an editor, with an implementation like this:

package com.commonsware.todo

class ToDoModel {
}

Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.