July 2015
Beginner to intermediate
600 pages
18h 59m
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 15.7.
Listing 15.7 Adding string resources (strings.xml)
Read now
Unlock full access