It seems to be the name. Remembering from android documentation. If your layout is result_profile.xml
<LinearLayout ... >
<TextView android:id="@+id/name" />
<ImageView android:cropToPadding="true" />
<Button android:id="@+id/button"
android:background="@drawable/rounded_button" />
</LinearLayout>
ViewBinding will generate ResultProfileBinding
.
If view binding is enabled for a module, a binding class is generated for each XML layout file that the module contains. Each binding class contains references to the root view and all views that have an ID. The name of the binding class is generated by converting the name of the XML file to Pascal case and adding the word "Binding" to the end.
So, with that in mind. if your layout is activity_note_list
it will generate ActivityNoteListBinding class or something like that. In your code, you are setting ContentNoteListBinding
class. Try to replace ContentNoteListBinding
with ActivityNoteListBinding
. Also, if it does not solve the problem. Try to add the code from console log. it has more details about the error.
Update
If you want to handle View or ViewGroup which are include in your activity/fragment over <include>
tag, you can access these views almost directly. You need to add an Id in this tag <include>
. And then you will have access to these components: For example:
This is a activity_note_list.xml
........
<include
id="+@id/ly_content_list_note"
layout="@layout/content_list_note"/>
........
And content_note_list.xml
<listView
id="+id/listNotes"
.......
/>
Now in your Activity class, you can access in this way:
binding.lyContentListNote.listNotes
As you can see, first access directly to the id of the container, which is ly_content_list_note
and then all the view components inside that, in this case listNotes
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…