简体   繁体   中英

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);

                }

            }
        }
});

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM