ListView内item与Button共存的点击监听问题
2016-03-11 12:34
561 查看
ListView内item与Button共存的点击监听问题
2016-03-11 12:34179人阅读 评论(0)
收藏
举报
分类:
android(14)
版权声明:本文为博主原创文章,未经博主允许不得转载。
最近写ListView,在其中的item中加入了ImageView和Button。发现ListView的点击事件突然不可以了,这是因为加入其它widget后,ListView的itemclick事件将无法触发,被其它widget的click事件屏蔽。
首先说明我的ListView的item布局中包含:TextView、Button
res/layout/item.xml
[html]
view plain
copy
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tauthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="名字"/>
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="15dp"
android:layout_marginRight="25dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher"/>
</LinearLayout>
以上是我的item布局文件
一开始我按照以前的经验,在ImageButton中加入了android:focusable="false" ,测试还是不行。感觉挺郁闷,
后来我通过查找资料,在最外层的布局中加入了 android:descendantFocusability="blocksDescendants",果然就可以了
另外我测试只单单在最外层加上:android:descendantFocusability="blocksDescendants"。也是不行的。
最后整理结论得:
1、在最外层布局中加入:android:descendantFocusability="blocksDescendants"
2、在Button、ImageButton,或者有相同特点的控件中加入:android:focusable="false"
两者缺一不可
相关文章推荐
- ListView内item与Button共存的点击监听问题
- 实践出真理
- 2016.3.9高项作业
- 第一次上机实验1—2
- ubuntu安装php mcrypt扩展
- SQL Server 表变量和临时表的简述
- FILE不是C语言关键字
- 关于 JavaScript prototype __proto__ 一点总结
- iOS点击屏幕使tableview、scrollview回到顶部
- 如何用好GitHub中的Watch、Star和Fork
- ffmpeg音频播放代码示例-avcodec_decode_audio4
- 获取顶层UIViewController
- 不想让某个进程访问某个文件或文件夹
- bash: mysql: command not found
- 如何在Unity5.0 下实现贴图材质的Animation动画功能
- coreData-reason = "The model used to open the store is incompatible with the one used to create the
- 当质数大于3时,证明质数的平方减1总能被24整除
- ThreadLocal理解
- adapter万能适配器
- 六.GIT遇到问题及知识点补充