Android-奇怪的复选框行为

Android-奇怪的复选框行为,android,Android,我遇到了以下问题:在我的Android应用程序中,我使用一个表来显示一些信息。此信息还包含2个布尔值,显示为复选框。加载表时,复选框会正常工作,但一旦我更改接口方向,即使数据值为false,两个复选框也会被选中 该表的定义如下: <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/table_properties" android:layout_width="fi

我遇到了以下问题:在我的Android应用程序中,我使用一个表来显示一些信息。此信息还包含2个布尔值,显示为复选框。加载表时,复选框会正常工作,但一旦我更改接口方向,即使数据值为false,两个复选框也会被选中

该表的定义如下:

<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/table_properties"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffffff"  
/>

以及该表中的单个布尔行:

<TableRow
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>   
    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"      
        android:id="@+id/text_jobprop_name" 
        style="@style/text_list_black"      
        android:layout_height="fill_parent"
        android:textSize="12dp"         
        android:padding="3dp"
        android:singleLine="false"  
        android:gravity="center_vertical"
        android:background="@color/table_property_name_background"  
        android:layout_weight="0.7"     
        android:layout_width="0dp"
    />  
    <LinearLayout
        android:layout_height="wrap_content"
        android:gravity="left"
        android:layout_marginRight="5dp"
        android:layout_marginLeft="10dp"
        android:layout_weight="1"   
        android:layout_width="0dp"
        android:background="@color/white">
        <CheckBox
            xmlns:android="http://schemas.android.com/apk/res/android"      
            android:id="@+id/chckbox_jobprop_value" 
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:clickable="false"   
            android:layout_marginLeft="10dp"                    
        />
    </LinearLayout>
</TableRow>

在活动的onCreate方法中,我调用了一个函数来设置表的所有值。我知道每次更改接口方向时都会调用此函数,但我调试了它,并且数据值没有更改

有什么提示、想法吗

谢谢

在活动的onCreate方法中,我调用一个函数 表的所有值。我知道这个函数叫做 每次我改变界面方向,但我调试了它和 数据值不会更改

这是真的,但是试着在onResume方法中设置复选框。。。如果没有:何时调用super.onCreate

在活动的onCreate方法中,我调用一个函数 表的所有值。我知道这个函数叫做 每次我改变界面方向,但我调试了它和 数据值不会更改

这是真的,但是试着在onResume方法中设置复选框。。。如果没有:什么时候调用super.onCreate?

像这样尝试

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
 savedInstanceState.putBoolean("MyBoolean1",cb1.isChecked());
 savedInstanceState.putBoolean("MyBoolean2",cb2.isChecked());
  super.onSaveInstanceState(savedInstanceState);
}
 @Override
public void onCreate(Bundle savedInstanceState) {
 .....
 boolean myBoolean1 = savedInstanceState.getBoolean("MyBoolean1");
 // now check its value and put the value in your checkbox..
在onCreate中,得到如下值

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
 savedInstanceState.putBoolean("MyBoolean1",cb1.isChecked());
 savedInstanceState.putBoolean("MyBoolean2",cb2.isChecked());
  super.onSaveInstanceState(savedInstanceState);
}
 @Override
public void onCreate(Bundle savedInstanceState) {
 .....
 boolean myBoolean1 = savedInstanceState.getBoolean("MyBoolean1");
 // now check its value and put the value in your checkbox..
现在它会像预期的那样工作,我想…

像这样试试

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
 savedInstanceState.putBoolean("MyBoolean1",cb1.isChecked());
 savedInstanceState.putBoolean("MyBoolean2",cb2.isChecked());
  super.onSaveInstanceState(savedInstanceState);
}
 @Override
public void onCreate(Bundle savedInstanceState) {
 .....
 boolean myBoolean1 = savedInstanceState.getBoolean("MyBoolean1");
 // now check its value and put the value in your checkbox..
在onCreate中,得到如下值

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
 savedInstanceState.putBoolean("MyBoolean1",cb1.isChecked());
 savedInstanceState.putBoolean("MyBoolean2",cb2.isChecked());
  super.onSaveInstanceState(savedInstanceState);
}
 @Override
public void onCreate(Bundle savedInstanceState) {
 .....
 boolean myBoolean1 = savedInstanceState.getBoolean("MyBoolean1");
 // now check its value and put the value in your checkbox..

现在它将如预期的那样工作,我想…

万分感谢,这也为我解决了:)我在别处听说onRestoreInstanceState也可能工作。仍然-奇怪的行为,很难搜索:/万分感谢,这也为我解决了:)我在其他地方听说onRestoreInstanceState也可以工作。仍然-奇怪的行为,难以搜索:/