2013-05-14 63 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