title: hide layout checkbox is checked android
body: <p>I am trying to simply hide a linear layout if a checkbox is clicked. I have defined function and onClick attribute calls it which is also tested with toast but when I try hiding the layout, it doesn't do anything.</p>
  
  <p>The layout.xml:</p>
  
  <pre><code>&lt;CheckBox
          android:id="@+id/cbguest"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="0.9"
          android:onClick="itemClicked"
           /&gt;
  </code></pre>
  
  <p>In MainActivity.java</p>
  
  <pre><code>int[] i = {0};
  public void itemClicked(View v) {
      LinearLayout layoutguest1 = (LinearLayout) findViewById(R.id.guestlayout);
  
      if (lns[0]%2 == 0) {
          Toast.makeText(getApplicationContext(),"Visible", Toast.LENGTH_SHORT).show();
          layoutguest1.setVisibility(View.VISIBLE);
          lns[0]+=1;
      }
      if (lns[0]%2 != 0) {
          layoutguest1.setVisibility(View.GONE);
          Toast.makeText(getApplicationContext(),"Gone", Toast.LENGTH_SHORT).show();
          lns[0]+=1;
      }
  
  }
  </code></pre>