0

我以这种方式将数据存储在 xml 数组中

<resources>
    <array name="myarray">
        <item>
            <item>attribute1</item>
            <item>attribute2</item>
            <item>and so on</item>
        </item>
        <item>
            <item>attribute1</item>
            <item>attribute2</item>
            <item>and so on</item>
        </item>
        <item>
            <item>attribute1</item>
            <item>attribute2</item>
            <item>and so on</item>
        </item>
    </array>
</resources>

// in program
TypedArray array = getResources().obtainTypedArray(R.array.myarray);

当我在程序中调用 array.getIndexCount() 时它返回 0,有什么问题?

4

1 回答 1

1

Please try this. According to the android docs:

  <resources>
  <string-array name="planets_array">
    <item>Mercury</item>
    <item>Venus</item>
    <item>Earth</item>
    <item>Mars</item>
  </string-array>
  </resources>

To get this resource"

Resources res = getResources();
String[] planets = res.getStringArray(R.array.planets_array);

This may help..

于 2013-07-02T17:16:17.507 回答