Home > database >  onClickListener on RelativeLayout doesn't work
onClickListener on RelativeLayout doesn't work

Time:11-13

        <RelativeLayout
            android:id="@ id/reviews_root"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/border"
            android:clickable="true">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@ id/reviews"
                android:paddingTop="20dp"
                android:layout_width="match_parent"
                android:layout_height="400dp"/>
        </RelativeLayout>

I'm using above code in xml.

    binding.apply {
        reviewsRoot.setOnClickListener {
            NavigateWithItemName(itemname)
            Log.i("click","click") //doesn't work
        }
    }

I'm using above code in onCreateView in Fragment. I want to setOnClickListener on RelativeLayout, but it doesn't work when I click RelativeLayout..

I don't know why.

CodePudding user response:

The RecyclerView lying over the RelativeLayout is consuming the clicks that are intended to be handled by the layout. To prevent that You would have to set:

android:clickable="false"

on the RecyclerView. Now the layout will consume the clicks.

CodePudding user response:

it's binding.reviewsroot.setOnClickListener{}

there is no space for binding

  • Related