-1

I have the activity that have two Layout the first Layout VISIBLE and second is Gone. Now I have ImgView when pressed it open the Layout Gone , change Image to close Image and when press again close this Layout . I am wondering how I can use the same Img View for opening and closing Layout?

nour ha
  • 9
  • 3

1 Answers1

2

try this

create boolean openLayout=true; at the top of activity

imgView.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        if(openLayout){
             layout1.setVisibility(View.VISIBLE);
             layout2.setVisibility(View.Gone);
             openLayout = false;}
        else{
             layout1.setVisibility(View.Gone);
             layout2.setVisibility(View.VISIBLE);
             openLayout = true;
        }
});
Aditya
  • 3,525
  • 1
  • 31
  • 38
Kapil Parmar
  • 881
  • 8
  • 19