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.

1
  • add these to the progressIndicator, android:clickable="true" android:focusable="true" Commented Mar 15, 2021 at 16:11

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.