Cause: couldn't make a guess for com.example.data_...
# native
k
Cause: couldn't make a guess for com.example.data_binding.myClickhandler this is the error i am getting when i try to create onclick action listnerer with help of data binding i have give the code below (edited)
Copy code
[2:18 PM] <?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="Person"
            type="com.example.data_binding.Person" />

        <variable
            name="Clickhandler"
            type="com.example.data_binding.myClickhandler" />
    </data>

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@{Person.name}"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="16dp"

        android:text="@{Person.email}"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.525"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:layout_constraintVertical_bias="0.278">

    </TextView>

    <Button
        android:onClick="@{Clickhandler::onButton1Clicked}"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/click_me"
        app:layout_constraintBottom_toTopOf="@+id/textView2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:layout_constraintVertical_bias="0.574">

    </Button>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
package com.example.data_binding;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.example.data_binding.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding activityMainBinding ;
    private myClickhandler myclickhandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Person p1 = new Person("Jack" , "<mailto:jack2419@gmail.com|jack2419@gmail.com>");
        activityMainBinding = DataBindingUtil.setContentView(
                this , R.layout.activity_main
        );
        activityMainBinding.setPerson(p1);
        myclickhandler = new myClickhandler(this);
        activityMainBinding.setClickhandler(myclickhandler);
    }
}
package com.example.data_binding;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

public class myClickhandler {

    Context context;

    public myClickhandler(Context context) {
        this.context = context;
    }

    public void onButton1Clicked(View view) {
        Toast.makeText(context, "Button Clicked", Toast.LENGTH_SHORT).show();
    }
}