全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

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会覆盖子类控件而直接获得焦点

  我们使用的是第三个。


# listview点击item无响应  # listview  # item点击  # Android中如何取消listview的点击效果  # Android 中ListView的Item点击事件失效的快速解决方法  # listview点击无效的处理方法(推荐)  # 子类  # 的是  # 是在  # 不需要  # 第三个  # 时才  # 解决办法  # 有三种  # 最常用  # 其子  # 情况下  # dp  # paddingRight  # paddingLeft  # paddingBottom  # paddingTop  # layout_width  # wrap_content  # res  # layout_height 


相关文章: 表情包在线制作网站免费,表情包怎么弄?  c++23 std::expected怎么用 c++优雅处理函数错误返回【详解】  专业商城网站制作公司有哪些,pi商城官网是哪个?  建站之家VIP精选网站模板与SEO优化教程整合指南  成都网站制作价格表,现在成都广电的单独网络宽带有多少的,资费是什么情况呢?  如何在IIS7上新建站点并设置安全权限?  如何在万网自助建站平台快速创建网站?  大连 网站制作,大连天途有线官网?  如何快速搭建响应式可视化网站?  javascript中对象的定义、使用以及对象和原型链操作小结  公司网站制作需要多少钱,找人做公司网站需要多少钱?  建站之星免费模板:自助建站系统与智能响应式一键生成  简历在线制作网站免费版,如何创建个人简历?  如何通过商城免费建站系统源码自定义网站主题?  如何获取开源自助建站系统免费下载链接?  广东企业建站网站优化与SEO营销核心策略指南  宝塔新建站点为何无法访问?如何排查?  如何快速搭建高效服务器建站系统?  番禺网站制作公司哪家值得合作,番禺图书馆新馆开放了吗?  制作网站怎么制作,*游戏网站怎么搭建?  济南网站制作的价格,历城一职专官方网站?  建站之星安装模板失败:服务器环境不兼容?  定制建站策划方案_专业建站与网站建设方案一站式指南  阿里云网站搭建费用解析:服务器价格与建站成本优化指南  如何在Golang中实现微服务服务拆分_Golang微服务拆分与接口管理方法  阿里云高弹*务器配置方案|支持分布式架构与多节点部署  建站之星收费标准详解:套餐费用及年费价格表一览  制作网站的公司有哪些,做一个公司网站要多少钱?  如何用免费手机建站系统零基础打造专业网站?  如何高效利用亚马逊云主机搭建企业网站?  电影网站制作价格表,那些提供免费电影的网站,他们是怎么盈利的?  如何通过虚拟机搭建网站?详细步骤解析  制作门户网站的参考文献在哪,小说网站怎么建立?  ,如何利用word制作宣传手册?  python的本地网站制作,如何创建本地站点?  php json中文编码为null的解决办法  网站制作怎么样才能赚钱,用自己的电脑做服务器架设网站有什么利弊,能赚钱吗?  网站设计制作书签怎么做,怎样将网页添加到书签/主页书签/桌面?  如何生成腾讯云建站专用兑换码?  如何获取上海专业网站定制建站电话?  建站之星后台密码遗忘或太弱?如何重置与强化?  制作假网页,招聘网的薪资待遇,会有靠谱的吗?一面试又各种折扣?  如何选择适配移动端的WAP自助建站平台?  开心动漫网站制作软件下载,十分开心动画为何停播?  香港服务器如何优化才能显著提升网站加载速度?  制作网站的过程怎么写,用凡科建站如何制作自己的网站?  武汉外贸网站制作公司,现在武汉外贸前景怎么样啊?  中山网站制作网页,中山新生登记系统登记流程?  Swift中循环语句中的转移语句 break 和 continue  南京做网站制作公司,南京哈发网络有限公司,公司怎么样,做网页美工DIV+CSS待遇怎么样? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。