ListView中Button的点击事件冲突
2016-04-26 16:51
405 查看
< ? xml version = "1.0" encoding = "utf-8" ? >
< LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"
android:layout_width= "fill_parent" android:layout_height= "fill_parent"
android:padding= "10dip" android:orientation= "vertical" >
< ListView android:id= "@+id/listView" android:layout_width= "fill_parent"
android:layout_height= "fill_parent" / >
< / LinearLayout>
在< RelativeLayout>中
android:descendantFocusability= "blocksDescendants"
和< ImageButton>中
android:focusable = "false"
这两项的设置很关键,如果不设置,将导致ListView的ItemClick事件将无法触发,该事件被ImageButton的click事件屏蔽了。
适配器中的布局文件
< LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android"
android:layout_width= "fill_parent" android:layout_height= "fill_parent"
android:padding= "10dip" android:orientation= "vertical" >
< ListView android:id= "@+id/listView" android:layout_width= "fill_parent"
android:layout_height= "fill_parent" / >
< / LinearLayout>
在< RelativeLayout>中
android:descendantFocusability= "blocksDescendants"
和< ImageButton>中
android:focusable = "false"
这两项的设置很关键,如果不设置,将导致ListView的ItemClick事件将无法触发,该事件被ImageButton的click事件屏蔽了。
适配器中的布局文件
< ? xml version = "1.0" encoding = "utf-8" ? > < RelativeLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:padding= "5dip" android:descendantFocusability= "blocksDescendants" > //关键设置 < ImageButton android:id= "@+id/ItemCloseWin" android:layout_alignParentRight= "true" android:layout_alignTop= "@+id/ItemWinName" android:layout_alignBottom= "@+id/ItemWinName" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:background= "#e0000000" android:gravity= "left|center_vertical" android:focusable= "false" //关键设置 android:src= "@android:drawable/ic_menu_close_clear_cancel" / > < TextView android:id= "@+id/ItemWinName" android:layout_toRightOf= "@+id/ItemImage" android:layout_toLeftOf= "@+id/ItemCloseWin" android:layout_alignTop= "@+id/ItemImage" android:layout_alignBottom= "@+id/ItemImage" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:gravity= "left|center_vertical" android:textSize= "20dip" android:text= "title" / > < / RelativeLayout> |
相关文章推荐
- 网络接入技术(摘抄)
- 个人工作总结08
- 校园分期市场的机遇与风险4
- 最近读书总结
- Odoo 8 绿色版在 CentOS 自动安装及以服务方式启动方法 原文地址:
- iis7.5 ftp设置
- PAT 1027. 打印沙漏
- POJ 2376 Cleaning Shifts 区间覆盖
- Android-SubMenu子菜单
- 迭代
- MPI库安装、配置及测试程序
- STM32定时器单脉冲输出
- Eclipse 自动生成作者时间等注释
- 线程池二
- 校园分期市场的机遇与风险3
- 跨域资源共享 CORS 详解
- 这样教育孩子
- SharePoint 2013 FIMSynchronizationService 2137 " FIMSynchronizationService"
- 如何取消win7工具栏预览功能?win7系统关闭工具栏预览功能的方法
- 总结代码开发完成–> 同步、更新、上传SVN –>服务器上部署整个流程