Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 15  Implicit Intents


Before you can create these implicit intents, there is some setup to do in CriminalIntent:



  • add CHOOSE SUSPECT and SEND CRIME REPORT buttons to CrimeFragment’s layouts

  • add an mSuspect field to the Crime class that will hold the name of a suspect

  • create a crime report using a set of format resource strings


Adding Buttons


You are going to start by updating CrimeFragment’s layout to include new buttons for accusation
and tattling: namely, a suspect button and a report button. First, add the strings that these buttons will
display.


Listing 15.1  Adding button strings (strings.xml)


%1$d crimes
Choose Suspect
Send Crime Report

In layout/fragment_crime.xml, add two button widgets, as shown in Figure 15.2. Notice that in this
diagram we are not showing all of the LinearLayout’s children so that you can focus on the new and
interesting parts of the diagram on the right.


Figure 15.2  Adding suspect and crime report buttons
(layout/fragment_crime.xml)


At this point, you can preview the updated layout or run CriminalIntent to confirm that your new
buttons are in place.

Free download pdf