2012-07-04 64 views
1

我正在其含有ExpandableListView,一個CheckedTextViewListView定製視圖:如何將多個UI元素合併到android中的listview中?

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/filtersDialogView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:minHeight="200dp" 
    android:orientation="vertical" > 

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

    <CheckedTextView 
     android:id="@+id/onlyShowAvailableItemsCheckedTextView" 
     android:layout_width="match_parent" 
     android:layout_height="?android:attr/listPreferredItemHeight" 
     android:checkMark="?android:attr/listChoiceIndicatorMultiple" 
     android:gravity="center_vertical" 
     android:paddingLeft="8dip" 
     android:paddingRight="8dip" 
     android:text="@string/OnlyShowAvailableItems" /> 

    <ListView 
     android:id="@+id/categoriesListView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</LinearLayout> 

的問題是,所述CheckTextView是固定的,這兩個列表獨立地滾動(這是正常的該佈局) 。此外,當我從ExpandableListView展開一個列表項時,CheckedTextView和其他ListView隱藏。當我展開第一個列表的一個元素(第二個列表的單元格不能展開時)時,我想製作一個包含所有這些元素的單個列表,這些元素可以正確滾動和調整大小。我怎樣才能做到這一點?是否有可能無需修改CheckedTextView的列表和控制器的適配器? 謝謝

回答

1

我該怎麼做?是否有可能無需修改 列表的適配器和CheckedTextView的控制器?

我懷疑,特別是當你有兩個滾動視圖,ExpandableListViewListView。我認爲你唯一的選擇是一個特殊的適配器,將模擬上面的佈局。我有一個自定義的ExpandableListView適配器,我修改成可以模擬上面的佈局的東西。這是生物,所以可能會有一些錯誤(我已經測試了一下),當然還有其他一些工作要做。代碼示例它有點大,所以我把它放在這裏https://gist.github.com/3046887

+0

相當真棒:) – Alexis

+0

我想擺脫出現在不擴展的組視圖上的下拉圖標。我怎樣才能做到這一點? – Alexis

+1

@jafar不幸的是,這是你必須自己做的事情之一。因爲你擁有所有帶有圖標的組或者所有組都沒有圖標,你必須管理自己的狀態。我修改了從我的答案鏈接的代碼再看看它(檢查'getGroupView'方法)。您基本上必須從所有組中刪除圖標,然後在擴展組的佈局文件中添加一個「ImageView」。畢竟,註冊一個'OnGroupClickListener'並根據當前狀態修改可繪製的圖像,摺疊/展開。 – Luksprog

相關問題