2011-04-28 72 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),则复选框将继续清除其状态。