0

我已经通过了本教程:

Android:在 XML 中创建和填充 ListView 项

我想在 xml 中初始化 ListView 而不是代码。

我的 array.xml 文件:

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

    <string-array name="anyArray">
        <item>one</item>
        <item>two</item>
        <item>three</item>
    </string-array>

</resources>

我的 activity_main.xml 文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:entries="@array/anyArray" >
    </ListView>

</RelativeLayout>

当我切换到布局时,我收到此警告

Couldn't resolve resource @array/anyArray

并且不显示任何项目。我该如何解决这个问题?

4

1 回答 1

2

您的资源名称应仅包含 [a-z0-9._]。将您的重命名Array为所有小写字符。

于 2012-10-09T08:34:26.613 回答