因为自带的listView不能满足项目需求,通过实现自己的Adapter去继承ArrayAdapter 来实现自定义ListView的Item项目。
成都创新互联公司主营武义网站建设的网络公司,主营网站建设方案,App定制开发,武义h5小程序定制开发搭建,武义网站营销推广欢迎武义等地区企业咨询出现点击ListView的每一项都不会执行setOnItemClickListener 里面的onItemClick 方法。
原因是item里面存在一些子控件,默认点击获取的焦点跑去子控件去了,点击失效。
解决办法:
在item的根目录加入android:descendantFocusability="blocksDescendants"
<?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" android:descendantFocusability="blocksDescendants"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dp"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@drawable/message_oc" /> <TextView android:id="@+id/textTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title" android:textSize="25dp" android:layout_marginLeft="15dp"/> <TextView android:id="@+id/textDate" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" android:text="date" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/textMessage" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textMultiLine" android:text="message" android:textSize="20dp"/> </LinearLayout> </LinearLayout>
网站名称:Android自定义ListView单击事件失效的解决方法-创新互联
URL标题:https://www.cdcxhl.com/article18/hodgp.html
成都网站建设公司_创新互联,为您提供域名注册、服务器托管、建站公司、动态网站、网站制作、标签优化
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联