Show/hide views with checkbox
Posted
by DixieFlatline
on Stack Overflow
See other posts from Stack Overflow
or by DixieFlatline
Published on 2010-04-24T09:56:43Z
Indexed on
2010/04/24
10:33 UTC
Read the original article
Hit count: 326
Hi!
I want to show or hide some elements (textviews and edittexts) with checkbox. I set their visibility to gone in layout file. Showing them when user checks the box works, but the when user unchecks it, they don't hide. (android 1.5 and 1.6)
My code:
cb=(CheckBox)findViewById(R.id.cek);
cb.setOnClickListener(new OnClickListener() { // checkbox listener
public void onClick(View v) {
// Perform action on clicks, depending on whether it's now checked
if (((CheckBox) v).isChecked()) {
tv1.setVisibility(0); //visible==0
et3.setVisibility(0);
} else if (((CheckBox) v).isChecked() == false) {
tv1.setVisibility(2); //gone=2
et3.setVisibility(2);
}
}
});
© Stack Overflow or respective owner