2013-05-14 69 views
0

我想使用ExpandableListView,在组视图中我需要一个textview和一个复选框(复选框在右边)。 我看到的问题是groupIndicator视图不再可点击 - 点击它不会再扩大组。如果我删除复选框,那么groupIndicator接收事件并且组可扩展。与另一个接收某种焦点的View相同,例如EditText。 这里是包含ExpandableListView片段的布局:ExpandableListView groupIndicator被禁用了CheckBox

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ExpandableListView 
     android:id="@+id/categoryList" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </ExpandableListView> 

</RelativeLayout> 

在组的布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white_background" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/txtCategoryGroup" 
     android:layout_width="0dip" 
     android:layout_height="@dimen/items_filter_group_height" 
     android:layout_marginLeft="45dp" 
     android:layout_marginRight="20dp" 
     android:layout_weight="1" 
     android:gravity="center_vertical|left" 
     android:textIsSelectable="false" /> 

    <!-- 
    <CheckBox 
     android:id="@+id/cbGroup" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 
    </CheckBox> 
    --> 


</LinearLayout> 

...,如果你觉得有用,孩子的布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="@dimen/items_filter_child_height" 
    android:background="@color/white_background" 
    android:orientation="horizontal" > 

    <CheckBox 
     android:id="@+id/cbProperty" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 
    </CheckBox> 

</LinearLayout> 

附件是我得到的布局如果该复选框是取消注释: enter image description here

点击红色标记的groupIndicator不会扩展该组。留下它评论扩展它。如上所述:奇怪的是,EditText也会发生同样的情况。

的解决办法是设置groupIndicator到@null和TextView的大院向左绘制设置为响应有关ExpandableListView#OnGroupCollapseListener#OnGroupExpandListener的东西,但我不是这样的事情,开心写的代码。

谢谢!

回答

1

将android:descendantFocusability =“blocksDescendants”放在组和子组件的LinearLayout中。

+0

感谢您的快速解决方案! – gunar 2013-05-14 08:01:52