I would really like to set the layout depending on which combination of two checkboxes are selected. Since there are four possible states, I have four layouts to display items underneath the checkboxes, if selected. I have made this work using four classes, but there must be a more efficient way to do this.
Basically, I would like to have drop-down EditTexts for user input displayed under the checkboxes only if they are selected. If the setContentView statements are replaced with the commented ones, I can cycle through any combination of checkboxes, but as the code is, only one layout change is able to be made and I don't understand why. Please help with any suggestions.
**I realize the CompoundButton object is unused here.
public class First extends Activity implements OnCheckedChangeListener{
CheckBox emailBox,smsBox;
@Override public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_1);
emailBox=(CheckBox)findViewById(R.id.checkBox_1);
smsBox=(CheckBox)findViewById(R.id.checkBox_2);
emailBox.setOnCheckedChangeListener(this);
smsBox.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(CompoundButton compound,boolean isChecked){
if(!emailBox.isChecked()&&!smsBox.isChecked()){
setContentView(R.layout.activity_1);
// Toast.makeText(First.this,"None Checked",Toast.LENGTH_SHORT).show();
}
if(emailBox.isChecked()&&!smsBox.isChecked()){
setContentView(R.layout.activity_2);
// Toast.makeText(First.this,"Email Checked",Toast.LENGTH_SHORT).show();
}
if(smsBox.isChecked()&&!emailBox.isChecked()){
setContentView(R.layout.activity_3);
// Toast.makeText(First.this,"Sms Checked",Toast.LENGTH_SHORT).show();
}
if(emailBox.isChecked()&&smsBox.isChecked()){
setContentView(R.layout.activity_4);
// Toast.makeText(First.this,"Both Checked",Toast.LENGTH_SHORT).show();
}
}
}