Reputation: 43
I added in my build.gradle file following:
android {
...
buildFeatures {
viewBinding = true
}
...
}
}
I have a activity with many, many views (the customer want it so), and this throws following error:
Is there a solution for this problem?
Upvotes: 2
Views: 1656
Reputation: 2377
I have solved this separating some views by creating another layout. Let's say you have 500 views included TextView and so on inside your activity.xml.
Step you can follow is create new layout. Example content_layout_a.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ll"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
<!-- Some of your views here -->
</LinearLayout>
At this xml, you put some of the view like 100 views. If you have still exceeds views, maybe create another content layout.
Next, at your activity.xml. You will just need to the content by using include
. Make sure to include ID, so you can use binding to call it.
binding.includeItemA.textViewA
Example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ll"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
<!-- Some of your views here -->
<!-- Here you include your another content for other views -->
<include
android:id="@+id/include_item_a"
layout="@layout/content_layout_a"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@+id/view_line"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
</LinearLayout>
Then, try to Make Module
. Hope this one helps,
Upvotes: 1
Reputation: 396
It appears there is a limit to the number of views in a layout that will work with viewbinding. In my case I had a very large layout with many views. To ignore viewbinding for a specific layout add
tools:viewBindingIgnore="true"
to the root view of the layout. Just use an alternate method other than viewbinding to access the views in large layout.
Upvotes: 3