Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android frame layout click listener not working

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.

like image 853
Bipin Gawand Avatar asked Oct 14 '17 12:10

Bipin Gawand


2 Answers

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" />
like image 122
Pankaj Lilan Avatar answered Oct 29 '22 19:10

Pankaj Lilan


You are using it wrong. Try using:

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

    // Other layouts there

</FrameLayout>
like image 35
Akhilesh Awasthi Avatar answered Oct 29 '22 19:10

Akhilesh Awasthi