zoukankan      html  css  js  c++  java
  • ListView点击事件不响应。

    LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:descendantFocusability="blocksDescendants"
        android:orientation="horizontal" >
        <ImageView
            android:id="@+id/rowIV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_marginLeft="10dp"
            >
        </ImageView>
        <TextView
            android:id="@+id/rowTV"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            >     
        </TextView>
         <CheckBox
             android:id="@+id/rowCheckBox"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginRight="5dp" />
    
    </LinearLayout>
    

      

     如果你的自定义ListViewItem中有Button或者Checkable的子类控件的话,那么默认focus是交给了子控件,而ListView的Item能被选中的基础是它能获取Focus,也就是说我们可以通过将ListView中Item中包含的所有控件的focusable属性设置为false,这样的话ListView的Item自动获得了Focus的权限,也就可以被选中了

        我们可以通过对Item Layout的根控件设置其android:descendantFocusability=”blocksDescendants”即可,这样Item Layout就屏蔽了所有子控件获取Focus的权限,不需要针对Item Layout中的每一个控件重新设置focusable属性了,如此就可以顺利的响应onItemClickListener中的onItemClick()方法了。

    也可以将每个子控件写成 android:focusable="false"的,让控件失去焦点。

  • 相关阅读:
    LiveCD 是指用光盘就能启动并运行的系统
    漂亮的代码配色方案
    编程语言基础知识梗概
    监听器在游戏开发中的应用消息回调
    游戏业现状
    PS 1.x 中的寄存器
    Irrlicht(鬼火引擎)中多设备的支持
    关于《3D管线导论》这本书
    D3DPOOL
    c++虚函数表探究
  • 原文地址:https://www.cnblogs.com/LuckStarShine/p/2643471.html
Copyright © 2011-2022 走看看