I'm trying to put a click listener on a ConstraintLayout but it's never fired.
I don't know why I tried to look about android:clickable
but I didn't get any better
This is what I have in my parent view:
<include
android:id="@+id/search_scanner"
layout="@layout/scan_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
The layout scan_button is the following:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/scan_layout"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:id="@+id/scan_button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_registration_social_networks"
android:backgroundTint="@color/orange"
android:paddingHorizontal="15dp"
android:paddingVertical="5dp"
android:layout_marginRight="10dp">
<ImageView
android:id="@+id/scan_button_image"
android:layout_width="32dp"
android:layout_height="32dp"
android:paddingLeft="5dp"
android:src="@drawable/icon_scan"
android:layout_gravity="center"/>
<TextView
android:text="@string/scan_book"
android:textColor="@color/colorAccent"
android:textStyle="bold"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/scan_book_text"
android:textColor="@color/grey"
android:layout_marginTop="10dp"
android:lines="2"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scan_button"/>
</androidx.constraintlayout.widget.ConstraintLayout>
And this is what I'm doing about the listener:
search_scanner.setOnClickListener {
startActivity(Intent(context, ScannerActivity::class.java))
}
If you have some answers about it, I'll be glad!
EDIT : I solved it ! I just add an elevation on my layout because the scan layout was at the same level with a ListView (either the listview was empty). So it's working !
Thanks guys for your help