首页 > 解决方案 > Android TextView:与另一个具有相同 ID 的标签冲突

问题描述

我对 Android XML 文件有疑问,需要您的帮助。我有以下代码:

 <TextView
        android:id="@+id/textViewA"
        android:layout_width="95dp"
        android:layout_height="35dp"
        android:text="A"
        android:textColor="#000000"
        android:textSize="22dp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.012"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.671" />

    <TextView
        android:id="@+id/textViewS"
        android:layout_width="95dp"
        android:layout_height="35dp"
        android:text="S"
        android:textColor="#000000"
        android:textSize="22dp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.012"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.584" />

所以基本上我有两个TextView。当我编译时,我收到错误消息:

'<TextView id='@+id/textView'> conflicts with another tag that has the same ID'

当我单击错误的相应行时,会显示这两个 TextView。我不太明白这一点,因为他们没有相同的 ID。他们曾经有相同的ID,但我改变了它,仍然出现问题。也许这与我刚刚启用的 ViewBinding 有关?我会很感激每一条评论。

更新:我意识到实际上与 ViewBinding 有关,因为我还可以看到以下信息:

Found data binding error(s):

[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\T.D\\AndroidStudioProjects\\BarApp\\BarApp_Projekt\\app\\src\\main\\res\\layout\\activity_cocktail_ytest.xml","pos":[{"line0":48,"col0":4,"line1":61,"col1":52}]}
[databinding] {"msg":"\u003cTextView id\u003d\u0027@+id/textView\u0027\u003e conflicts with another tag that has the same ID","file":"C:\\Users\\T.D\\AndroidStudioProjects\\BarApp\\BarApp_Projekt\\app\\src\\main\\res\\layout\\activity_cocktail_ytest.xml","pos":[{"line0":121,"col0":4,"line1":134,"col1":52}]}

但我仍然不知道错误的原因。我的意思是他们绝对没有相同的ID。

标签: androidxmltextviewandroid-viewbinding

解决方案


使缓存无效并重新启动 android studio 将对您有所帮助。


推荐阅读