简体   繁体   中英

Disable response of root view in android

I've got a ListView with several rows. Every row consists of 7 TextViews which react to onClick() events.

This all works perfectly fine but when the user clicks on the margins of the row, where no TextView catches the onClick() event, the root view - a LinearLayout - get's highlighted .

This is normal behaviour of course but as nothing happens by clicking there I don't want the Linear Layout to be highlighted. Is there any way of disabling this behaviour but keep catching the onClick() events on the TextView s?

(The onClick listener is set inside the adapters getView() method)

Here some extract of the xml file. As one can see I've tried some things but they don't work.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"

    android:longClickable="false"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false">


    <TextView
        android:id="@+id/listelement_weekoverview_tv_mo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:layout_weight="1"
        android:background="@drawable/weeklylist_rndrectangle"
        android:gravity="center_horizontal"
        android:singleLine="false"
        android:textColor="@color/appcolor_red_base" />

        ...
</LinearLayout>

unclicked version 点击版本 clicked version 未点击的版本

I've found a solution.

Simply overwrite the isEnabled (int position) method in your custom Adapter like this:

@Override
public boolean isEnabled (int position) {
    return false;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM