Android ListView的item点击无响应的解决方法
假设listitem里面包含button或者checkbox等控件,默认情况下listitem会失去焦点,导致无法响应item的事件,最经常使用的解决的方法
是在listitem的布局文件里设置descendantFocusability属性。
item的布局文件:
<? xml version="1.0" encoding="utf-8"? >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:descendantFocusability="blocksDescendants"><!--加入这个属性-->
<CheckBox
android:id="@+id/history_item_checkbt"
android:layout_height="30dp"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:checked="false"
>
</CheckBox> <ImageView
android:id="@+id/history_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/history_item_checkbt"
android:background="@drawable/item_icon">
</ImageView> <Button
android:id="@+id/history_item_edit_bt"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="编辑"
android:textColor="#ffffff"
android:textSize="14sp"
android:background="@drawable/button_bg">
</Button> <TextView
android:id="@+id/history_item_time_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#565C5D"
android:textSize="14sp"
android:text="10-01 10:20"
android:layout_marginRight="5dp"
android:layout_toLeftOf="@id/history_item_edit_bt">
</TextView> <TextView
android:id="@+id/history_item_title_tv"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_centerVertical="true"
android:textColor="#565C5D"
android:textSize="14sp"
android:text="xxxxxxxxXXXXXXXXXXXXXXXX"
android:ellipsize="end"
android:maxLines="1"
android:layout_toRightOf="@id/history_item_image"
android:layout_toLeftOf="@id/history_item_time_tv"
android:layout_marginLeft="3dp">
</TextView>
</RelativeLayout>
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.

该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。
属性的值有三种:
beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup仅仅有当其子类控件不须要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
我们使用的是第三个。
Android ListView的item点击无响应的解决方法的更多相关文章
- Android ListView的item背景色设置以及item点击无响应等相关问题
Android ListView的item背景色设置以及item点击无响应等相关问题 在Android开发中,listview控件是非常常用的控件,在大多数情况下,大家都会改掉listview的ite ...
- Android ListView中Item点击事件失效解决方案
欢迎关注公众号,每天推送Android技术文章,二维码如下:(可扫描) 在平常的开发过程中,我们的ListView可能不只是简单的显示下文本或者按钮,更多的是显示复杂的布局,这样的话,我们就得自己写布 ...
- 使用PullToRefreshListView时遇到Item点击事件失效问题 解决方法
最近在自己的项目中使用到了以下开源项目: https://github.com/nanchen2251/pullToRefreshDemo 相关介绍博客如下: http://www.cnblogs.c ...
- DEDECMS织梦后台更新网站栏目无反应一键更新无响应的解决方法
很多站长朋友反应,经常会遇到DEDECMS织梦后台更新网站栏目无反应和一键更新无响应的问题,这个问题的所在就是在于恢复了数据或者覆盖了织梦后台文件之后,点击一键更新完全没反应,或者生成栏目的时候其他都 ...
- rpm yum 等命令无响应的解决方法
yum 安装查询任何东西, rpm 安装查询任何东西,执行后无任何反应,直接卡住,也没任何错误信息给出,只能杀掉进程 # yum install XXXX # yum clean all # rpm ...
- Win7下IE11点击无反应的解决方法
平台:win7 sp1 32bit 问题:点击Internet Explorer在开始菜单.快捷栏的图标和安装目录下的程序均没有反应,鼠标在变成漏斗后恢复原状再无反应.但搜狗浏览器和360浏览器下使用 ...
- IE8下使用webuploader点击无反应的解决方法。
在IE8开头添加如下代码. <meta http-equiv="X-UA-Compatible" content="IE=edge"> 即可解决,亲 ...
- slxna,游戏页面切到后台回来后返回sl页面导致sl页面无响应,解决方法。
slxna在wp7上表现很好,因为那会xna还是微软的亲儿子.但是到wp8时代,微软丢弃xna,不管不问了.但是丢之前没有把兼容搞的完美,以致有很多隐秘的坑,说不定就踩到了. 我这个游戏的sl页面用了 ...
- dedecms 安装后 管理后台ie假死 无响应的解决方法
在网站后台(我的是dede)uploads/emplets/index_body.htm中找到并注释掉以下代码: <script type=”text/javascript”>functi ...
随机推荐
- mysql5大引擎之间的区别和优劣之分
数据库引擎介绍 MySQL数据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎,就必须重新编译MYSQL.在缺省情况下,MYSQL支持三个引擎:ISAM.MYISAM和HEAP.另 ...
- 08C++函数
函数 4.1 概述 一个较大的程序不可能完全由一个人从头至尾地完成,更不可能把所有的内容都放在一个主函数中.为了便于规划.组织.编程和调试,一般的做法是把一个大的程序划分为若干个程序模块(即程序文件) ...
- Python3中assert断言
一般的用法是: assert condition 用来让程序测试这个condition,如果condition为false,那么raise一个AssertionError.逻辑上等于: if not ...
- Java 调用存储过程 返回结果集
这里使用Oracle数据库的thin连接. 下面是存储过程SQL 1 createorreplaceprocedure proc3(stid in student.stuid%type, stname ...
- Bootstrap table的基础用法
一.官方文档 Bootstrap 中文网:http://www.bootcss.com/ Bootstrap Table 中文网 : http://bootstrap-table.wenzhixin. ...
- Go:slice
一.切片创建方式 func main() { // 创建切片方式1 // 让切片引用一个数组 array := [...]int{1, 2, 3, 4} slice1 := array[1:3] fm ...
- LVS-NAT负载均衡PHP应用(Wordpress、Discuz)
1 实验拓扑 2 需求 RS-01和RS-02对外提供WEB服务. RS-01搭建LAMP,PHP通过http模块方式提供. RS-02搭建LAMP,PHP通过fpm方式提供. RS-01和RS-02 ...
- Python接口测试中通过登录接口获取实时token
1.封装login_token 2.headers:对应登录请求头部信息 3.request_param:登录的参数数据 4.json.dumps:将一个Python数据结构转换为JSON 5.dic ...
- matplotlib.pyplot.pcolormesh
matplotlib.pyplot.pcolormesh(*args, alpha=None, norm=None, cmap=None, vmin=None, vmax=None, shading ...
- 绑定IP 绑定设备
首先引别人的组播测试如下 1. 一个udp client可以同时往多个组播地址发送数据,多个udpclient可以同时往一个组播发数据. 2. 本地udp必须监听组播端口,否则收不到数据.3. 一个u ...