版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Mr_GLY_di/article/details/53224737
如果listview列表中有一个按钮或者子布局中有按钮,那么点击子item时,列表的点击事件将不会被触发,因为点击事件被Button点击事件屏蔽了,因此无法点击。
解决:
在ItemLayout的根部局加上属性android:descendantFocusability= “blocksDescendants”
在需要点击的控件上如Button加上属性 android:focusable=”false”
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability= "blocksDescendants"//在这设置layout
android:layout_margin="10dp"
android:background="#fff"
android:orientation="vertical" >
<GridView
android:id="@+id/frag_home_item_gv"
android:layout_width="wrap_content"
android:focusable="false"//子控件设置为false
android:layout_height="180dp"
android:horizontalSpacing="20dp"
android:numColumns="3"
android:verticalSpacing="10dp" >
</GridView>
</LinearLayout>