このようなxmlで単純な配列を作成する方法を知っています
<resources>
<string-array name="countries_array">
<item>Afghanistan</item>
<item>Albania</item>
<item>Algeria</item>
<item>American Samoa</item>
<item>Andorra</item>
<item>Angola</item>
<item>Anguilla</item>
<item>Antarctica</item>
</string-array>
</resources>
そして、コードでこのように初期化します
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries_array);
textView.setAdapter(adapter);
しかし、単なる文字列ではなく、より多くのアイテムを格納したいので、単純な配列ではなく配列リストを格納する方法が必要です。
以下のように
<resources>
<Share>
<name>Apple</name>
<currentRate>5.69</currentRate>
<changeToday>-0.11</changeToday>
<changeTodayPercent>-0.02</changeTodayPercent>
<timeUpdated>2012,12,06,18,00,00</timeUpdated>
<Share>
<Share>
<name>Microsoft</name>
<currentRate>5.88</currentRate>
<changeToday>0.19</changeToday>
<changeTodayPercent>+0.09</changeTodayPercent>
<timeUpdated>2012,12,06,18,00,00</timeUpdated>
<share>
...
</resources>
setMethods を介して設定する必要がある次の変数を持つ Share.java というクラスが既にあります
public class ShareHolding {
private String name;
private double currentRate;
private double changeToday;
private double changeTodayPercent;
private GregorianCalendar timeUpdated;
}
それらをarraylistに追加します
ArrayList<Share> allShares = new ArrayList<Share>();
allShares.getShare(0).setName("I want to access my xml file here and add the first shares name here");