繁体   English   中英

在Android中禁用根视图的响应

[英]Disable response of root view in android

我有几行的ListView 每行包含7个对onClick()事件作出反应的TextViews

这一切都很好,但是当用户单击行的空白处(没有TextView捕获onClick()事件)时, 根视图 LinearLayout - get突出显示

当然,这是正常的行为,但是如果单击此处没有任何反应,则我不想突出显示“线性布局”。 有什么方法可以禁用此行为,但是可以继续捕获 TextView上的onClick()事件吗?

(onClick侦听器在适配器的getView()方法中设置)

这里是xml文件的一些摘录。 可以看到,我已经尝试了一些方法,但是它们不起作用。

<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>

未点击的版本 点击版本 点击版本 未点击的版本

我找到了解决方案。

只需像这样在您的自定义适配器中覆盖isEnabled (int position)方法:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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