Activity
starts with the layout activity_home
and the CheckBox
unchecked. When I touch% color, the layout becomes CheckBox
, but activity_home_avancado
remains unchecked. On the second touch, it is checked and > layout remains as the advanced one.
On the third tap, the Checkbox
is cleared, but the active layout remains being CheckBox
. Why these two errors?
Follow 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 activity_home_avancado
present in the two XML files:
<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)