Search code examples
javaandroidandroid-viewandroid-buttonandroid-looper

Changing the visibility of views one at a time with a button


I have three views which visibility is currently set to view.setVisibility(view.GONE) and I have a button which I want to change the visibilities to visible one at a time as the user keeps clicking the button. I think I have to use a for loop centred on the button click but I don't know how. Any ideas will be appreciated.


Solution

  • int i = 0;
    
    onClick(View v){
       switch(++i){
           case 1:
             view1.setVisibility(View.GONE);
             break;
           case 2:
             view2 setVisibility(View.GONE);
             break;
           case 3:
             view3.setVisibility(View.GONE);
             i = 0;
             break;
          }
        }