March 2013
Beginner to intermediate
580 pages
16h 11m
English
The last preliminary is to create a template crime report that can be configured with the specific crime’s details. Because you will not know a crime’s details until runtime, you must use a format string with placeholders that can be replaced at runtime. Here is the format string you will use:
<string name="crime_report">%1$s! The crime was discovered on %2$s. %3$s, and %4$s
The %1$s, %2$s, etc. are placeholders that expect string arguments.
In code, you will call getString(…) and pass in the format string and four other strings in the order in which they should replace the placeholders.
First, in strings.xml, add the strings shown in Listing 21.3.
Listing 21.3 Add string resources (strings.xml)
<string name="crime_suspect_text">Choose ...
Read now
Unlock full access