2
To Activity
is started with the layout activity_home
and the CheckBox
unchecked. When I touch CheckBox
, the layout becomes the activity_home_avancado
, however the Checkbox
remains unmarked. At the second touch, she is marked and the layout remains as the advanced.
On the third touch, the CheckBox
is unmarked, but layout active remains being the activity_home_avancado
. Why these two mistakes?
Follows the code:
public class HomeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
final CheckBox checkBoxAvancado = (CheckBox) findViewById(R.id.modoavancado_cb);
checkBoxAvancado.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (checkBoxAvancado.isChecked()) {
setContentView(R.layout.activity_home_avancado);
}
else {
setContentView(R.layout.activity_home);
}
}
});
} //fecha onCreate
}
And the same CheckBox
present in the two archives XML:
<CheckBox
android:id="@+id/modoavancado_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textColor="#7F7F7F"
android:text="@string/modoavancado" />
(nothing appears in Logcat)