2011-04-28 46 views
0

我有一個2行列表XML,第一行也有一個複選框。這些數據不會被保存,只是在您列出的任務中檢查列表中的項目。2行列表XML帶複選框

我有2個問題。當我檢查第一個複選框時,列表的下一行也會被檢查。該複選框沒有ID,但必須有一些說明它的第一行的一部分或其他內容?

此外,當我改變方向屏幕刷新,我想停止複選框沒有保存。

這裏是XML

<?xml version="1.0" encoding="utf-8"?> 

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

<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:orientation="horizontal"> 

    <CheckBox android:text="" android:paddingRight="-10sp" 
     android:layout_marginRight="-10sp" android:layout_weight=".1" 
     android:textColor="@color/ndList" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"> 

    </CheckBox> 

    <TextView android:id="@+id/Ltext1" android:textColor="@color/ndList" 
     android:layout_width="wrap_content" android:layout_weight="2" 

     android:layout_height="wrap_content" android:layout_marginLeft="6dip" 
     android:layout_marginTop="6dip" android:text="ONE" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

</LinearLayout> 

<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:orientation="horizontal"> 

    <TextView android:id="@+id/Ltext2" android:textColor="@color/ndList" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_below="@+id/Ltext1" android:layout_alignLeft="@+id/Ltext1" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="TWO" /> 
</LinearLayout> 

</LinearLayout> 

回答

0

我不完全遵循這個問題的第一部分,與複選框狀態保存的第二部分如下回答:

活動被關閉並在方向改變時重新開始。

使用onSaveInstanceState(Bundle)來存儲選定的選項並在onCreate(Bundle)中恢復該選擇。

onSaveInstanceState(Bundle bundle) { 
bundle.putBoolean("checked", checkBox.isChecked()); 
} 


onCreate(Bundle bundle) { 
if (bundle.containsKey("checked")) { 
checkBox.setChecked(bundle.getBoolean("checked")); 
} 
0

你應該確保,您更新所有可以改變你intemrenderer其內容的意見。這必須在您的ListAdaptergetView方法中完成。
這也包括複選框。因此,如果您沒有持有複選框選中狀態的底層數據成員(您的商品數據中包含boolean),則複選框將繼續清除其狀態。