The following is the first few sections of a chapter from Exploring Android, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


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 GitHub 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” > “Java Class” from the context menu. This will bring up a dialog where we can define a new Java class. For the name, fill in DisplayFragment. For the superclass, fill in android.support.v4.app.Fragment. Click “OK” to create the class.

That will give you a DisplayFragment that looks like:

package com.commonsware.todo;

import android.support.v4.app.Fragment;

public class DisplayFragment extends Fragment {
}

Step #2: Instantiating the Fragment

The preview of this section is [REDACTED].

Step #3: Responding to List Clicks

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

Step #4: Displaying the (Empty) Fragment

The preview of this section took that left turn at Albuquerque.

Step #5: Creating an Empty Layout

The preview of this section is sleeping in.

Step #6: Setting Up Data Binding

The preview of this section is [REDACTED].

Step #7: Adding the Completed Icon

The preview of this section was eaten by a grue.

Step #8: Displaying the Description

The preview of this section will not appear here for a while, due to a time machine mishap.

Step #9: Showing the Created-On Date

The preview of this section is [REDACTED].

Step #10: Adding the Notes

The preview of this section was eaten by a grue.

Step #11: Populating the Layout

The preview of this section is [REDACTED].

What We Changed

The preview of this section may contain nuts.