androidstudio-ListView id字段没有考虑并产生错误



我有这样的ListView声明:

<ListView
    android:id="@id/android:list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

我已经将ListView的id字段设置为@id/android:list,但没有得到错误Your content must have a ListView whose id attribute is 'android.R.id.list'

这完全错了,我的朋友。

android:id属性中,您需要为小部件定义自己的id。所以,如果你想给id作为列表,那么它会像:

android:id="@+id/list"

android:list将指向android库中id为list的变量。

您给出的id不正确。

用途:android:id="@+id/listView"

当您创建一个新的视图时,您应该使用+来给出id。

相关内容

最新更新