I am getting started for using DataBinding
feature. I am facing problem with it.
Error:(21, 9) error: cannot find symbol class ContactL
Don't forget to add in app level gradle, apply plugin: 'kotlin-kapt'
I have got the same issue and I found that variable name and method were missing. Double check the layout file or look for build error that says DATABINDINGISSUE, or invalidate and restart android studio. It should work.
You need to add the tags into your Activity's Xml Layout.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name=""
type="" />
</data
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.letsnurture.ln_202.databindingdemo.ContactListActivity">
</android.support.design.widget.CoordinatorLayout>
</layout>
and then, add an android:id into your tag
After that, you'll have a ActivityContactListBinding object and you can access and bind variables on your included layouts.
your model just have getter and setter in androidX. else not find your model in view and show this bug
public class User {
String name;
public String getName() {
return name;
}
public User(String name) {
this.name = name;
}
}
I was calling my onClick
wrong, which caused this error. So I changed
android:onClick="@{listener.onDogClicked()}"
to
android:onClick="@{listener::onDogClicked}"
In my case I had the same issue but the reason was different. My onClick function was declared private in the activity class, so be sure that, if you are using a handler function inside the layout, the function must not be private.
// this will not be visible in the binded layout because it's private!
private fun mainButtonClick(view: View) {
if (viewModel.isRecording.value == true) {
stopRecordingAndPlaying()
} else {
startRecordingAndPlaying()
}
}