2011-12-02 73 views
0

我想向可擴展列表的父視圖添加一個按鈕。這是我對parentview的佈局。我需要一個可擴展列表的父視圖中的按鈕

<?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="wrap_content" 
    android:orientation="horizontal" > 

    <ImageView 
     android:id="@+id/explist_indicator" 
     android:layout_width="25dp" 
     android:layout_height="match_parent" 
     android:layout_weight=".25" 
     android:src="@drawable/expander_group" /> 

    <TextView 
     android:id="@+id/contacts" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:layout_weight="1" 
     android:paddingLeft="20dp" 
     android:text="@string/contacts" 
     android:textSize="28dp" > 
    </TextView> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight=".25" 
     android:background="@drawable/plus" 
     android:text="Button" /> 

</LinearLayout> 

我將按鈕添加到Java類像正常的,卻得到了一個空指針異常,當我嘗試添加一個監聽器。我添加此按鈕來選擇/取消選擇特定父級的所有子級。任何幫助都會很棒。

+0

您還需要發佈一些代碼 - 以及您的LogCat。 – kaspermoerch

回答

1

您可以添加一個自定義圖像作爲組下拉指示器,方法是簡單地創建下拉列表的圖像,然後通過它的組指示器屬性將其掛接到可擴展列表視圖。組指示符是一個可繪製的xml文件,用於定義state_expanded和drawable狀態使用的圖像。您仍然需要在代碼中爲可展開列表視圖在運行時設置組指示符。