0

My clicklistener is not working anymore when adding it to it's own layout file.

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    binding = DataBindingUtil.setContentView<ActivityMainBinding>(
        this, R.layout.activity_main
    ).apply {
        lifecycleOwner = this@MainActivity
    }
    binding.progressIndicatorLayout.progressIndicator.setOnClickListener {
        Log.d("","Hello")
    }
}

activity_main.xml:

<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <include
            android:id="@+id/progress_indicator_layout"
            layout="@layout/progress_indicator_layout" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

progress_indicator_layout:

<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:id="@+id/progressIndicator"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black"
        android:orientation="horizontal">

    </LinearLayout>
</layout>

I tried this solution and this solution but they are outdated / don't work.

Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94

1 Answers1

1

I tried to copy your code and it works completely fine. I think you just need to clean the project and Invalidate Caches / Restart.

If still not working try to check this.

newbie101
  • 65
  • 10