question
When using Android Studio 4.1, if comments are added between UI controls in the layout, and the comments contain "&" characters, viewBinding cannot recognize all controls after the comments:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<TextView
android:id="@+id/tvTest1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- & -->
<TextView
android:id="@+id/tvTest2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Solution
- Solution 1: Remove the "&" character.
- Solution 2: Upgrade Android Studio (tested with Android Studio 4.2 Beta 6 version, there is no related problem).