Android中列表视图的项点击没有反应的解决方法

  

如果stu_item.xml里面包括按钮或者复选框等控件,默认情况下的列表项会失去焦点,导致无法响应项目的事件,最常用的解决办法是在stu_item.xml的布局文件中设置descendantFocusability属性。

  

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

  

属性的值有三种:

        beforeDescendants: viewgroup会优先其子类控件而获取到焦点   afterDescendants: viewgroup只有当其子类控件不需要获取焦点时才获取焦点   blocksDescendants: viewgroup会覆盖子类控件而直接获得焦点   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android: layout_width=" match_parent "   android: layout_height=" 50 dp”   面向android:="水平"   android: descendantFocusability=" blocksDescendants "祝辞& lt; !——添加这个属性——比;   & lt; ImageView   android: id=癅 + id/img_head”   android: layout_width=" 50 dp”   android: layout_height=" 50 dp”   android: src=" https://www.yisu.com/zixun/@drawable dog2 "   android: scaleType=" centerCrop "   android: layout_marginRight=" 5 dp/比;   & lt; TextView   android: layout_width=" 0 dp”   android: layout_weight=" 1 "   android: layout_height=" wrap_content "   android: layout_gravity=" center_vertical "   android: id=癅 + id/tv_name”/比;   & lt; TextView   android: layout_width=" 0 dp”   android: layout_weight=" 1 "   android: layout_height=" wrap_content "   android: layout_gravity=" center_vertical "   android: id=癅 + id/tv_age”/比;   & lt;按钮   android: id=癅 + id/btn_delete”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_gravity=罢贰?   android:文本="删除”   android:输入textColor=" # ffffff "   android:背景=" # ff0000 "/比;   & lt;/LinearLayout>      

效果图:

  

 Android中列表视图的项点击没有反应的解决方法

  

  

以上所述是小编给大家介绍的Android中列表视图的项点击没有反应,希望对大家有所帮助,如果大家有任何疑问请给我留的言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

Android中列表视图的项点击没有反应的解决方法