ZaptechDev Kumar
ZaptechDev Kumar

Reputation: 164

Relative Layout not Clickable

below is my xml :

     <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:orientation="horizontal"
            android:weightSum="2">
     <RelativeLayout
            android:clickable="true"
            android:id="@+id/rel1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center">

            <com.app.thelist.view.CustomButton
                android:clickable="false"
                android:focusable="false"
                android:id="@+id/btn1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:layout_gravity="center"
                android:background="@android:color/transparent"
                android:text="btn1"
                android:textAllCaps="false"
                android:textColor="@color/txt_sub_title"
                android:textSize="@dimen/txt_barselection_size"
                app:FontEnum="regular" />

            <com.app.thelist.view.CustomTextView
                android:clickable="false"
                android:focusable="false"
                android:id="@+id/txt1"
                style="@style/RegularFont"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@id/btn_my_drinks"
                android:background="@drawable/border_gry_theme"
                android:padding="@dimen/dimen_3"
                android:text="00"
                android:textColor="@color/txt_sub_title"
                android:textSize="@dimen/txt_single_view_font" />

            <ImageView
                android:id="@+id/iv_bootm_selecter2"
                android:layout_width="match_parent"
                android:layout_height="7dp"
                android:layout_below="@id/btn1"
                android:scaleType="fitXY" />

        </RelativeLayout>
    <RelativeLayout
            android:clickable="true"
            android:id="@+id/rel1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center">

            <com.app.thelist.view.CustomButton
                android:clickable="false"
                android:focusable="false"
                android:id="@+id/btn1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:layout_gravity="center"
                android:background="@android:color/transparent"
                android:text="btn1"
                android:textAllCaps="false"
                android:textColor="@color/txt_sub_title"
                android:textSize="@dimen/txt_barselection_size"
                app:FontEnum="regular" />

            <com.app.thelist.view.CustomTextView
                android:clickable="false"
                android:focusable="false"
                android:id="@+id/txt1"
                style="@style/RegularFont"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@id/btn_my_drinks"
                android:background="@drawable/border_gry_theme"
                android:padding="@dimen/dimen_3"
                android:text="00"
                android:textColor="@color/txt_sub_title"
                android:textSize="@dimen/txt_single_view_font" />

            <ImageView
                android:id="@+id/iv_bootm_selecter2"
                android:layout_width="match_parent"
                android:layout_height="7dp"
                android:layout_below="@id/btn1"
                android:scaleType="fitXY" />

        </RelativeLayout>
    </LinearLayout>

I have done findViewby id and added click listener to relative layout.. but it not taking click event.. instead click event is generating while i am clicking on textview inside relative layout.

What might be the isssue ?

Thanks.

Upvotes: 2

Views: 5889

Answers (1)

VikasGoyal
VikasGoyal

Reputation: 3376

The click event is passed from Child to parent. If any child is clickable then first child get the click event and if the child is not clickable then the click event pass to the parent.

If the parent wants click event before child then it needs to override onInterceptTouchEvent(MotionEvent ev); in parent view class.

But if don't want to go with this then a simple solution is made child non-clickable. Please find the edited XML code in your case.

<RelativeLayout
        android:clickable="true"
        android:id="@+id/rel1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:focusable="true"
        android:focusableInTouchMode="true">

        <com.app.thelist.view.CustomButton
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_gravity="center"
            android:background="@android:color/transparent"
            android:text="btn1"
            android:clickable="false"
            android:focusable="false"
            android:textAllCaps="false"
            android:textColor="@color/txt_sub_title"
            android:textSize="@dimen/txt_barselection_size"
            app:FontEnum="regular" />

        <com.app.thelist.view.CustomTextView
            android:id="@+id/txt1"
            style="@style/RegularFont"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/btn_my_drinks"
            android:background="@drawable/border_gry_theme"
            android:padding="@dimen/dimen_3"
            android:text="00"
            android:clickable="false"
            android:focusable="false"
            android:textColor="@color/txt_sub_title"
            android:textSize="@dimen/txt_single_view_font" />

        <ImageView
            android:id="@+id/iv_bootm_selecter2"
            android:layout_width="match_parent"
            android:layout_height="7dp"
            android:clickable="false"
            android:focusable="false"
            android:layout_below="@id/btn1"
            android:scaleType="fitXY" />

    </RelativeLayout>

Upvotes: 1

Related Questions