Книга: Beginning Android

Arrays

Arrays

Array resources are designed to hold lists of simple strings, such as a list of honorifics (Mr., Mrs., Ms., Dr., etc.).

In the resource file, you need one string-array element per array, with a name attribute for the unique name you are giving the array. Then, add one or more child item elements, each of which have a single text element with the value for that entry in the array:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <string-array name="cities">
  <item>Philadelphia</item>
  <item>Pittsburgh</item>
  <item>Allentown/Bethlehem</item>
  <item>Erie</item>
  <item>Reading</item>
  <item>Scranton</item>
  <item>Lancaster</item>
  <item>Altoona</item>
  <item>Harrisburg</item>
 </string-array>
 <string-array name="airport_codes">
  <item>PHL</item>
  <item>PIT</item>
  <item>ABE</item>
  <item>ERI</item>
  <item>RDG</item>
  <item>AVP</item>
  <item>LNS</item>
  <item>AOO</item>
  <item>MDT</item>
 </string-array>
</resources>

From your Java code, you can then use Resources.getStringArray() to get a String[] of the items in the list. The parameter to getStringArray() is your unique name for the array, prefixed with R.array. (e.g., Resources.getStringArray(R.array.honorifics)).

Оглавление книги

Оглавление статьи/книги

Генерация: 0.141. Запросов К БД/Cache: 2 / 0
поделиться
Вверх Вниз