这个问题整了很久,今天终于解决了
问题描述:
点击ListView的Item无效果
问题分析:
Item的布局代码是这样的:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/llRight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:gravity="right"
android:orientation="horizontal" >
<Button
android:id="@+id/btMark"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@android:color/holo_orange_dark"
android:text="Mark" />
<Button
android:id="@+id/btDelete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@android:color/holo_green_dark"
android:text="Delete" />
</LinearLayout>
<LinearLayout
android:id="@+id/llLeft"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="tvTitle" />
</LinearLayout>
</FrameLayout>
按理说点击这个Item的时候ListView背景应该改变,但是现在什么效果都没有。第一想到的是会不会Item被盖住了,所以给Item设置个padding,运行下padding是有了,但是还是不能点击:
其实始终心里都感觉不会是这个原因。
既然不是这个原因,还会是什么呢?想不到原因,就又把自定义的listview和adapter重新写了一遍,仔细检查了代码,折腾了好久,问题依旧。实在没办了,就用很久以前学习的方法试试吧(虽然这个时候感觉就这几个元素不削用这种方法):把ItemView中的元素全部删除,然后一个一个加入,这个是否发现了问题:当加入两个Button按钮所在布局的时候问题就出现了。会是什么原因呢?也许你可能会想到ListView和Button是不是有冲突之类,但是悲剧的是我压根就没这么想过,原因很简单:我这么干过——在listview中加button,当时没出现过问题,参考这里。然后找同事帮看下,果然是ListView和Button的问题。现在想想,应该是之前写的时候这个问题被别人给屏蔽(解决了),到我这没体现
解决办法:
android:descendantFocusability
Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.
Must be one of the following constant values.
Constant
Value
Description
beforeDescendants
|
0 |
The ViewGroup will get focus before any of its descendants. |
afterDescendants
|
1 |
The ViewGroup will get focus only if none of its descendants want it. |
blocksDescendants
|
2 |
The ViewGroup will block its descendants from receiving focus. |
This corresponds to the global attribute resource symboldescendantFocusability
.
总结下下:
再遇到这种问题,还是第一时间请教别人吧
分享到:
相关推荐
listview 拖动 item 排序,参照了DragSortListView:可拖动排序的listview DragSortListView:可拖动排序的listview
Android review listview 显示 单击事件
android ListView Item点击展开子项效果
关于listview item重用导致图片重复加载 图片重新请求
Android Listview Item上下拖动位置
如标题,dialog中嵌套listview,并响应每一行的单击事件。测试的过程中,发现如果listview里面有radiobutton控件的话,listview的item无法点击的问题。 亲们,如果一定要这样做的话,用TextChecked控件代替...
ListView Item 排序 长按选中 移动排序
listview item选中删除,全选,取消
android listview item 选择
listview item点赞和收藏,listview item中控件的点击事件,未涉及到网络请求,网络请求请自己在点击事件中添加,代码虽然简单但是思路很重要哦 listview item点击事件
如果listitem里面包括button或者checkbox等控件,默认情况下listitem会失去焦点,导致无法响应item的事件,怎么解决呢?下面小编给大家分享下listview点击item无响应的解决办法
ListView Item多布局的实现
动态添加、移除ListView的itemView!非常流畅哦
仿微信的ListView item可左右滑动效果
Android ListView的单击和长按时,避免同时执行
经常需要在项目中实现以下效果,点击listview中子item的颜色会改变
Android ViewPager实现画廊效果ListView Item添加动画集合
Android ListView Item滑动进入动画效果,仿照的事窝牛装修app的动画,很酷炫。可参考我的博客:http://blog.csdn.net/zuiwuyuan?viewmode=list
自定义listview,实现item特效,通过左右滑动删除listview item效果
android listview item 左右滑动删除