Android frame layout click listener not working

Bipin Gawand picture Bipin Gawand · Oct 14, 2017 · Viewed 8.4k times · Source

I've got a FrameLayout with two nested LinearLayouts. I want an onClickListener() for FrameLayout. After a search I got a solution clickable="false".

This is my Layout file:

<FrameLayout
    android:id="@+id/flOuter"
    android:paddingLeft="@dimen/half_margin"
    android:paddingRight="@dimen/half_margin"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:clickable="false"
        android:gravity="center"
        android:id="@+id/flAddIdProof"
        android:background="@drawable/add_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:clickable="false"
            android:id="@+id/ivIcon"
            android:src="@drawable/ic_add_black_48dp"
            android:background="@drawable/add_button_border"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        </LinearLayout>

    <LinearLayout
        android:clickable="false"
        android:id="@+id/llLinear"
        android:alpha="0.5"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:enabled="false"
            android:clickable="false"
            android:drawablePadding="@dimen/half_margin"
            android:drawableLeft="@drawable/ic_devices_black_24dp"
            android:hint="Identity Proof"
            android:inputType="none"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <EditText
            android:enabled="false"
            android:clickable="false"
            android:drawableLeft="@drawable/ic_border_color_black_24dp"
            android:hint="Identity Number"
            android:drawablePadding="@dimen/half_margin"
            android:inputType="none"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</FrameLayout>

Here is my click listener:

flOuter.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Toast.makeText(DeviceInMeeting.this, "detect", Toast.LENGTH_SHORT).show();
    }
});

I don't know how to debug for onClick listeners, clickable="false" is not working in my case.

Answer

Pankaj Lilan picture Pankaj Lilan · Oct 14, 2017

Try implementing android:clickable="true" in Following code snippet for FrameLayout

<FrameLayout    
   android:id="@+id/flOuter"
   android:clickable="true"
   android:focusable="true"
   android:foreground="attr/selectableItemBackground"
   android:paddingLeft="@dimen/half_margin"
   android:paddingRight="@dimen/half_margin"
   android:layout_width="match_parent"
   android:layout_height="wrap_content">

and adding android:clickable="false" in other nested layout.

<LinearLayout    
   android:id="@+id/flOuter"
   android:clickable="false" />