view longclick were abort by textView children

48 Views Asked by At

i have a LinearLayout that content textView, then i put LongClick to this linearlayout to show dialog, but only longclick to this layout outside of textview make dialog show, click in textview make nothing appear


    <LinearLayout
        android:id="@id/bubble"
        android:tag="69"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="30dp"
        android:layout_marginRight="30dp"
        android:descendantFocusability="blocksDescendants"
        android:layout_toEndOf="@id/messageUserAvatar"
        android:layout_toRightOf="@id/messageUserAvatar"
        android:orientation="vertical">

        <TextView
            android:id="@id/messageText"
            android:duplicateParentState="true"
            android:clickable="false"
            android:longClickable="false"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginEnd="4dp"
            android:layout_marginRight="4dp" />

can someone help

1

There are 1 best solutions below

0
Tensky On

I believe this happens because the TextView is above the Linear Layout. easy fix for this is to put a View on top of all of them maybe using FrameLayout then putting an empty view with transparent background and listen to click from that Empty view instead.

<View
    android:id="@+id/viewClickLayer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusable="true" />

and on the java

viewClickLayer.setOnClickListener {
        //do anything you want here
}