Android中ListView的item点击没有反应的解决方法-创新互联

如果stu_item.xml里面包括button或者checkbox等控件,默认情况下list的item会失去焦点,导致无法响应item的事件,最常用的解决办法是在stu_item.xml的布局文件中设置descendantFocusability属性。

铜官ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

该属性是当一个为view获取焦点时,定义viewGroup和其子控件两者之间的关系。

属性的值有三种:

 beforeDescendants:viewgroup会优先其子类控件而获取到焦点
 afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
 blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="50dp"
 android:orientation="horizontal"
 android:descendantFocusability="blocksDescendants"><!--添加这个属性--> 
 <ImageView
  android:id="@+id/img_head"
  android:layout_width="50dp"
  android:layout_height="50dp"
  android:src="@drawable/dog2"
  android:scaleType="centerCrop"
  android:layout_marginRight="5dp"/>
 <TextView
  android:layout_width="0dp"
  android:layout_weight="1"
  android:layout_height="wrap_content"
  android:layout_gravity="center_vertical"
  android:id="@+id/tv_name"/>
 <TextView
  android:layout_width="0dp"
  android:layout_weight="1"
  android:layout_height="wrap_content"
  android:layout_gravity="center_vertical"
  android:id="@+id/tv_age"/>
 <Button
  android:id="@+id/btn_delete"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="right"
  android:text="删除"
  android:textColor="#ffffff"
  android:background="#ff0000"
  />
</LinearLayout>

当前题目:Android中ListView的item点击没有反应的解决方法-创新互联
网页链接:https://www.cdcxhl.com/article42/dohohc.html

成都网站建设公司_创新互联,为您提供网站策划软件开发用户体验手机网站建设营销型网站建设品牌网站设计

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网页设计公司