Displaying an Item

We are storing things, like notes, in the ToDoModel that do not appear in the roster list. That sort of list usually shows limited information, with the rest of the details shown when you tap on an item in the list. That is the approach that we will use here, where we will show a separate fragment with the details of the to-do item when the user taps on the 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: Creating the Fragment

Once again, we need to set up a fragment.

Right-click over the com.commonsware.todo package in the java/ directory and choose “New” > “Kotlin File/Class” from the context menu. This will bring up a dialog where we can define a new Kotlin class. For the name, fill in DisplayFragment. For the kind, choose “Class”. Press Enter or Return to create the class.

That will give you a DisplayFragment that looks like:

package com.commonsware.todo

class DisplayFragment {
}

Then, have it extend the Fragment class:

package com.commonsware.todo

import androidx.fragment.app.Fragment

class DisplayFragment : Fragment() {
}

Prev Table of Contents Next

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