2012-04-03 3 views
2

다음과 같은 문제가 있습니다. Android 앱에서 테이블을 사용하여 정보를 표시하고 있습니다. 이 정보는 체크 박스로 표시되는 2 개의 부울 값도 포함합니다. 테이블이로드되면 체크 상자는 정상적으로 작동하지만 인터페이스 방향을 변경하자마자 데이터 값이 false 인 경우에도 두 확인란이 모두 선택됩니다.Android - 이상한 체크 박스 동작

테이블은 다음과 같이 정의된다 :

<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 방법을 테이블에 대한 값. 이 함수는 인터페이스 방향을 변경할 때마다 호출된다는 것을 알고 있지만 디버깅하고 데이터 값은 변경되지 않습니다.

힌트, 아이디어 등은 무엇입니까?

감사합니다.

답변

3

그리고 활동의 onCreate 메소드에서 나는 테이블의 모든 값을 으로 설정하는 함수를 호출합니다. 이 함수는 라고 불리우는 것을 알지만 인터페이스 방향을 변경할 때마다 디버깅을하고 데이터 값은 변경되지 않습니다.

사실 그렇지만 onResume 메서드에서 확인란의 설정을 시도해보십시오. 그렇지 않은 경우 : super.onCreate가 호출되는시기는 언제입니까?

+0

감사합니다, 효과가있었습니다. – Pathos

+0

천 가지 고마워요, 이것도 저를 위해 해결되었습니다 :) 나는 onRestoreInstanceState가 잘 작동하는 다른 곳을 듣습니다. 아직도 - 이상한 행동과 찾기가 어렵다 : / – Groxx

1

는 다음과 같이 시도 ..

@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); 
} 

과에서 onCreate에서

이 같은 값을 얻을 ..
@Override 
public void onCreate(Bundle savedInstanceState) { 
..... 
boolean myBoolean1 = savedInstanceState.getBoolean("MyBoolean1"); 
// now check its value and put the value in your checkbox.. 

지금 내가 생각하는 예상대로 작동합니다 ...