jueves, 27 de febrero de 2014

Android - First Steps VI


Arrays

In your project in the following path: res -> layout folder, create an Android XML file. 
Select from the wizard in Resource Type : Values and named the Xml file as "javafacts.xml".


The XML file must have the following structure:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="messages">
        <item>
First element</item>
        <item>Second element</item>
    </string-array>
</resources>


Get Array in code

In this case R.array.messages is by the name in defined in the XML file.
Resources resources = this.getResources();
        String[] javafacts =  resources.getStringArray(R.array.messages);



No hay comentarios:

Publicar un comentario