samedi 24 janvier 2015

How would I allow a CheckBox to show more options after being checked on Android Studio?

I currently have two CheckBox where if one is checked the other cannot be checked. I would like to be able to check one box, and the other CheckBox option would move towards the bottom of the screen to create space. How would I do this? Also, after it has created space, I would like to show more CheckBox options for each of the original CheckBoxes, how would I add these, and keep them hidden until the checkbox is clicked. Also, it would reverse if the checkbox is unchecked.


Essentially, I want to be able to click a checkbox, and have more checkbox options appear underneath.


This is my current code for the checkboxes:



final CheckBox chk1 = (CheckBox) findViewById(R.id.checkBox1);
final CheckBox chk2 = (CheckBox) findViewById(R.id.checkBox2);

chk1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
chk2.setChecked(false);
chk1.setChecked(b);
chk2.setAlpha(0.5f);
chk1.setAlpha(1f);
}
});

chk2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
chk1.setChecked(false);
chk2.setChecked(b);
chk1.setAlpha(0.5f);
chk2.setAlpha(1f);
}
});




Aucun commentaire:

Enregistrer un commentaire