Creating a UI Fragment

The steps to creating a UI fragment are the same as those you followed to create an activity:

  • compose an interface by defining widgets in a layout file

  • create the class and set its view to be the layout that you defined

  • wire up the widgets inflated from the layout in code

Defining CrimeFragment’s layout

CrimeFragment’s view will display the information contained within an instance of Crime. Eventually, the Crime class and CrimeFragment’s view will include many interesting pieces, but for this chapter, you just need a text field to contain the crime’s title.

Figure 7.14 shows the layout for CrimeFragment’s view. It consists of a vertical LinearLayout that contains an EditText. EditText is a widget that presents an area where ...

Get Android Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.