Android XML id“listView”未在任何地方定义

时间:2014-03-24 17:30:46

标签: java android 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.app.MainActivity$PlaceholderFragment" >

<ListView
    android:id="@+id/listOfLists"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button1"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/button" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@id/listView1"
    android:layout_alignParentTop="true"
    android:layout_alignRight="@+id/listView1"
    android:onClick="NewListActivity"
    android:text="New List v2" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/listView1"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/listView1"
    android:text="Receipts"
    android:onClick="ReceiptsActivity" />

</RelativeLayout>

我收到错误说

Multiple annotations found at this line:
    - The id "listView" is not defined anywhere. Did you mean one of {listView1, listView2} ?
    - error: Error: No resource found that matches the given name (at 'layout_alignEnd' with value '@id/

我没有使用listView,我正在使用listView1。

1 个答案:

答案 0 :(得分:1)

更改此

android:layout_alignEnd="@id/listView1"

android:layout_alignEnd="@id/listOfLists"

因为你有

<ListView
android:id="@+id/listOfLists"

同样在@+id/listOfLists

的其他地方替换

编辑:

使用

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.app.MainActivity$PlaceholderFragment" >

<ListView
    android:id="@+id/listOfLists"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button1"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/button" />

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignEnd="@id/listOfLists"
    android:layout_alignParentTop="true"
    android:layout_alignRight="@id/listOfLists"
    android:onClick="NewListActivity"
    android:text="New List v2" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@id/listOfLists"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@id/listOfLists"
    android:text="Receipts"
    android:onClick="ReceiptsActivity" />

</RelativeLayout>