CheckBox Text Does Not Change on Orientation Change
I have differing layout files (one in layout and one in layout-land) for a screen with the only difference being that some UI widgets in the files point to different string (longer string for landscape mode). For TextView widgets the correct resource Strings are displayed, but for CheckBoxes the text displayed stays the same during all orientation changes.
./layout/tabA.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/label1"
style="@style/TextBoxLabel.Header.WithInputsOnScreen"
android:text="@string/label1Short"
/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:layout_below="@id/label1"
android:text="@string/checkBox1Short"
/>
</RelativeLayout>
</ScrollView>
./layout-land/tabA.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/label1"
style="@style/TextBoxLabel.Header.WithInputsOnScreen"
android:text="@string/label1Long"
/>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:layout_below="@id/label1"
android:text="@string/checkBox1Long"
/>
</RelativeLayout>
</ScrollView>
So with the above, on an orientation change label1’s text changes between label1Short and label1Long. But checkBox1’s text stays the same as the text that was correct for the device orientation when the screen was first viewed.
Any thoughts? Thanks
Mike
CheckBox widget save it state even after configuration change (orientation change in your case). As solution of your problem you can define Activity’s onConfigurationChange method by yourself.