Download Teach Yourself Android Application Development in 24

Transcript
Implementing the Settings Screen Layout
Implementing the Settings Screen
Layout
To implement the settings screen, you begin by adding new resources to the project.
You then update the settings.xml layout resource to reflect the settings screen
design.
Adding New Project Resources
Screens with form fields seem to rely on more resources than most other screen
types. You need to add a number of new resources to support the settings screen. In
addition to the string, dimension, and color resources, you also need to add a new
type of resource: a string array.
Adding New String Resources
The settings screen relies on numerous new string resources. You add the following
text resources to the strings.xml resource file:
. Text for each setting’s TextView label (for example, “Nickname:”)
. Text for each Button control (for example, “Set
Password”)
. Text to display in a TextView control when the password is set or not set
. Text to display in a TextView control when the Date of Birth field is not set
. Text to display in a TextView control when the two Password fields match or
don’t match
. Text for each Gender option in the Spinner control (for example, “Male”)
After you have added these strings, save the strings.xml resource file.
Adding New String Array Resources
Spinner controls, like ListView controls, use data adapters. You have your gender
string resources defined, but you still need to group them into some sort of dataset.
The simplest dataset is an array (and the corresponding ArrayAdapter control). To
group the gender string resources (“Male”, “Female”, “Prefer Not To Say”)
together into an array, you create a new resource type called a String array.
To create a String array resource, you must add a new resource file called
/res/values/arrays.xml. Within this file, you create a new string-array element
called genders. Within this string-array element, you add three Item elements,
one for each string resource.
165