2012-02-18 28 views
2

這是我對ListView的每一行佈局:的ListView改變行

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/llRow" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 
<LinearLayout 
     android:id="@+id/llClosed" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" > 

Stuff Inside 

</LinearLayout> 

<LinearLayout 
     android:id="@+id/llOpen" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" > 

Stuff Inside 

</LinearLayout> 
</LinearLayout> 

的想法是,當我點擊一個ListView項目它集llClosedGonellOpenVisible使稍後用一些動畫我可以創建一個擴展的外觀。

protected void onListItemClick(ListView l, View v, int position, long id) { 
     super.onListItemClick(l, v, position, id); 
       View open = v.findViewById(R.id.llOpen); 
       View close = v.findViewById(R.id.llClosed); 
       close.setVisibility(View.GONE); 
     open.setVisibility(View.VISIBLE); 
} 

問題是,當我點擊第一行時,它不僅改變了第一行,而且還改變了第2行或第3行。什麼會造成這種情況?

求助:如果我在列表適配器llOpen.setVisibility(View.GONE)它將解決我的問題。

回答

0

好,一個問題是你有相同的ID android:id="@+id/llClosed"

在佈局中的所有元素有一個ID應該有一個唯一一個兩個線性佈局。嘗試android:id="@+id/llClosed1"android:id="@+id/llClosed2"

我很抱歉,但我不能確切地告訴你要完成什麼,但看起來你可能想嘗試expandablelistview類。退房:

http://techdroid.kbeanie.com/2010/09/expandablelistview-on-android.html

http://about-android.blogspot.com/2010/04/steps-to-implement-expandablelistview.html

+0

這是一個錯誤,當複製。線性佈局具有不同的ID。這個想法是,我點擊一行llClosed消失,並出現llOpen。像擴大行一樣。 – 2012-02-18 17:59:33