While using data binding , I am not able to get class MainActivityBinding
as per Data Binding Guide
My layout name is activity_main.xml
.
I am also see Android - DataBinding - How and when the Binding classes will be generated? but it can't help me.
Thanks to all for your answer.I found solution with ContentMainBinding
class name for data binding.
Lets me explain.
NOTE: While using layout with <include ...
here is <include layout="@layout/content_main"
having Data Binding functionality, the class name related to include layout name. Here is the ContentMainBinding
My layout file are as below:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.databindingdemo.app.MainActivity">
...
<include layout="@layout/content_main" />
...
</android.support.design.widget.CoordinatorLayout>
And content_main.xml is layout where I added my Data Binding layout code.
So instead of using MainActivityBinding
it can resolved with ContentMainBinding
The code which work for me is below:
//Code for data binding
ContentMainBinding contentMainBinding = DataBindingUtil.setContentView(this, R.layout.content_main);
user = new User("Pranay", "Patel", "demoemail@gmail.com", "9999999999");
contentMainBinding.setUser(user);
DONE.