zoukankan      html  css  js  c++  java
  • listview里面装了别的组件导致item点击无效问题的解决方案

    业务需要,在listview里面嵌了个gridview,结果悲催的发现,listview的item的点击事件没了,问了度娘好一会,终于拿到答案,在这里记录一下:

    Item中存在诸如ImageButton,Button,CheckBox等子控件(也可以说是Button或者Checkable的子类控件),此时这些子控件会将焦点获取到,所以常常当点击item时变化的是子控件,item本身的点击没有响应。

        这时候就可以使用descendantFocusability来解决啦,API描述如下:

    android:descendantFocusability

    Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.

    Must be one of the following constant values.

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

    属性的值有三种:

            beforeDescendants:viewgroup会优先其子类控件而获取到焦点

            afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点

            blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点

    答案就在这了,在Item布局的根布局加上android:descendantFocusability=”blocksDescendants”的属性就好了,至此listview点击的灵异事件告一段落。

  • 相关阅读:
    装饰者模式
    使用dom4j工具:读取xml(一)
    关于设计模式
    简单工厂模式
    Html 笔记
    数据库SQL归纳(三)
    windows上同时安装两个版本的mysql数据库
    MySQL的使用
    数据库SQL归纳(二)
    数据库SQL归纳(一)
  • 原文地址:https://www.cnblogs.com/dmhai/p/3225047.html
Copyright © 2011-2022 走看看