Godfryd Godfryd - 8 days ago 7
Android Question

setVisibility(View.Visible) not working after setting to invisible

setVisibility(View.INVISIBLE)
part is working fine, but when I press the radio button to bring back the visibility the items are not appearing. What am I missing?

rg = (RadioGroup) myView.findViewById(R.id.radioGroup);

rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.list:{

listSearch.setVisibility(View.VISIBLE);
editSearch.setVisibility(View.VISIBLE);

}
case R.id.order:{

listSearch.setVisibility(View.INVISIBLE);
editSearch.setVisibility(View.INVISIBLE);

}

}
}
});

Answer

Since you use a switch, you need to be carefull about when to stop.

You need to tell when to stop to read, each following case would be execute until you reach a break.

Here :

switch (checkedId){
    case R.id.list:
        ...
        break; // *** LINE A
    case R.id.order:
        ...                
}

Without LINE A, the following lines will be executed too, meaning you will set the view to VISIBLE then INVISIBLE on one call.

Comments