tags:

views:

86

answers:

1

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);
        }
    }
});
+2  A: 

Don't use magic numbers like 0 or 2. Use GONE, VISIBLE or INVISIBLE instead: Android Developers site

Maurits Rijk
It works with gone instead of magic numbers. Seems like another bug. Tnx
DixieFlatline
Glad it works. I don't think it is a bug. According to the documentation the value of GONE is 8 instead of the value 2 you used.
Maurits Rijk