Listing 310 Arraysxml used for defining cuisines and ratings

<?xml version="1.0" encoding="utf-8 " ?> <resources>

<array name= "cuisines"> O Define <array> elements

<item>American</item> C Define array <item> elements

<item>Barbeque</item>

<item>Chinese</item>

<item>French</item>

<item>German</item> <item>Indian</item> <item>Italian</item> <item>Mexican</item> <item>Thai</item> <item>Vegetarian</item> <item>Kosher</item> </array> </resources>

Arrays are defined as resources using an <array> element with a name attribute O and include any number of <item> child elements Q to define each array member. You can access arrays in code using the syntax shown in listing 3.1: String[] ratings = getResources().getStringArray(R.array.ratings).

Raw files and XML are also supported through resources. Using the res/raw and res/xml directories, respectively, you can package these file types with your application and access them through either Resources.openRawResource(int id) or Resources.getXml(int id).

Going past simple values for strings, colors, and dimensions and more involved but still straightforward structures for styles, arrays, raw files, and raw XML, the next type of resources we need to explore are animations.

0 0

Post a comment