禁用GridView项目完全单击

时间:2016-04-07 20:56:04

标签: android gridview onclick android-cardview

首先我在GridView内有一个CardViewGridView仅用于显示数据,项目不可点击。每个CardView都有一个点击事件,可以转到详细信息Activity

我的问题是,当用户点击GridView时,它不会转到详细信息Activity

我的CardView代码:

<android.support.v7.widget.CardView
android:id="@+id/card_view_geo"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_vertical_margin"
android:layout_marginRight="@dimen/activity_vertical_margin"
android:layout_marginTop="@dimen/horizontal_space_medium"
android:layout_marginBottom="@dimen/horizontal_space_small"
android:background="?attr/selectableItemBackground"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:layout_gravity="center"
cardUseCompatPadding="true"
cardElevation="3dp" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/vertical_space_small"
    android:paddingBottom="@dimen/vertical_space_medium"
    android:paddingLeft="@dimen/horizontal_space_medium"
    android:paddingRight="@dimen/horizontal_space_medium"
    android:orientation="vertical">

    <TextView
        android:id="@+id/text_geo_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/vertical_space_small"
        android:singleLine="true"
        android:textSize="@dimen/title_text_size"
        android:text="My Geo"/>

    <br.com.hbsis.indicadores.util.view.WrapContentGridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/grid_view_indicators"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:columnWidth="@dimen/grid_view_column_width"
        android:numColumns="auto_fit"
        android:verticalSpacing="@dimen/grid_view_spacing"
        android:horizontalSpacing="@dimen/grid_view_spacing"
        android:stretchMode="columnWidth"
        android:gravity="center"/>

</LinearLayout>

提前致谢

1 个答案:

答案 0 :(得分:0)

我的一位朋友帮我解决了问题。

我们已创建自定义Gridview并覆盖onTouchEvent方法。

public class CustomGridView extends GridView {

    ...

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return false;
    }
}