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.
The layout.xml:
<CheckBox
        android:id="@+id/cbguest"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.9"
        android:onClick="itemClicked"
         />
In MainActivity.java
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;
    }
}
 
     
     
     
    