首页 > 解决方案 > 如何为列表视图下的视图设置点击监听器

问题描述

我有一个它的listviewis ,在它的标题下有一个视图,我想在项目通过滚动之前点击它。headerheadertransparentlistview

我搜索了一些解决方案,例如:使用cancelablefocusable标题的属性并将这些值设置为 false;但问题仍然存在!

在这种特殊情况下,如何访问另一个视图下的视图的 onclick 监听器?

我想点击orderTypeLinearLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lightestGray"
android:orientation="vertical">

<LinearLayout
    android:id="@+id/rootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gray"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/headerLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.6"
        android:background="@color/gray"
        android:orientation="vertical"
        android:padding="10dp">

        <ImageView
            android:id="@+id/titleImageView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scaleType="centerInside"
            tools:ignore="ContentDescription,NestedWeights" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="20dp"
            android:orientation="horizontal">

            <LinearLayout
                android:id="@+id/orderTypeLinearLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                tools:ignore="UseCompoundDrawables">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/icon_arrow_drop_down_white"
                    tools:ignore="ContentDescription,RtlHardcoded" />

                <TextView
                    android:id="@+id/orderTypeTextView"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.5"
                    android:gravity="left"
                    android:textColor="@color/white"
                    android:textSize="16sp"
                    tools:ignore="RtlHardcoded" />
            </LinearLayout>

            <TextView
                android:id="@+id/userListTitleTextView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:gravity="right"
                android:textColor="@color/white"
                android:textSize="16sp"
                tools:ignore="RtlHardcoded" />
        </LinearLayout>
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.4"
        android:background="@color/gray" />
</LinearLayout>

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/scoreBoardSwipeRefresh"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ListView
        android:id="@+id/scoreBoardFragmentListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:alpha="1"
        android:divider="@null" />
</android.support.v4.widget.SwipeRefreshLayout>

标签: androidlistviewviewtouchonclicklistener

解决方案


推荐阅读