在此纪念下碰到的坑。GridView设置OnItemClickListener后没有效果。起初是怀疑被抢占了焦点,结果发现Item 的布局中没有checkbox和button这类控件。
在细细思考和多下实验中,发现,必须在GridView外层套个LinearLayout才能设置点击监听事件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="@+id/gv_goods"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="50dp"
android:numColumns="4"></GridView>
</LinearLayout>
</LinearLayout>
就是这么坑爹