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 to-do items is nice. However, right now, all of the to-do items are fake. We need to start allowing the user to fill in their own to-do items.
The first task is to set up an edit fragment. Just as we can click on a to-do
item in the list to bring up the details, we need to be able to click on something
in the details to be able to edit the description, notes, etc. So, just as we
created a DisplayFragment
in the preceding tutorial, here we will create an
EditFragment
and arrange to display it.
This tutorial has many similarities to the preceding one:
The differences come in the layout itself, as we have a different mix of
widgets than before. Plus, we need to add an icon to the DisplayFragment
, to
allow the user to request to edit that to-do item.
You might wonder “hey, shouldn’t we use inheritance or something here?” In
theory, we could. In practice, the DisplayFragment
is going to change quite
a bit in a later tutorial, and so we would have to undo the inheritance work
at that point anyway.
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.
For the third and last time, 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 EditFragment
.
For the superclass, fill in
android.support.v4.app.Fragment
. Click OK to create the class.
That will give you an EditFragment
that looks like:
package com.commonsware.todo;
import android.support.v4.app.Fragment;
public class EditFragment extends Fragment {
}
The preview of this section took that left turn at Albuquerque.
The preview of this section took that left turn at Albuquerque.
The preview of this section was whisked away by a shark-infested tornado.
The preview of this section is presently indisposed.
The preview of this section is in the process of being translated from its native Klingon.
The preview of this section was fed to a gremlin, after midnight.
The preview of this section is unavailable right now, but if you leave your name and number at the sound of the tone, it might get back to you (BEEEEEEEEEEEEP!).
The preview of this section may contain nuts.
The preview of this section was lost in the sofa cushions.
The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.
The preview of this section is in the process of being translated from its native Klingon.