title: Hide and show layout based on conditions in Android
body: <p>I am new to Android. I want to hide and show Linearlayout based on if else conditions. In my application I have taken 1 spinner. Based on selected spinner values I want my next layout hide or visible, but if it is once gone it not comes visible again.</p>
  
  <p>My code is:</p>
  
  <pre><code>    public class Expense extends Activity{
      Spinner datype;
  
      public void onCreate(Bundle b){
      super.onCreate(b);
      setContentView(R.layout.expense);
      mainlayout=(LinearLayout)this.findViewById(R.id.layout1);
      datype=(Spinner)findViewById(R.id.da_type);
      List&lt;String&gt;data1=new ArrayList&lt;String&gt;();
      data1.add("Local");
      data1.add("Ex-Station Double Side");
      data1.add("Ex-Station Single Side");
      data1.add("Out-Station Double Side");
      data1.add("Out-Station Single Side");
      ArrayAdapter&lt;String&gt;adapter=new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item,data1);
      adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
      datype.setAdapter(adapter);
      if(datype.getSelectedItem().toString().equals("Local")){
  
          mainlayout.setVisibility(LinearLayout.GONE);
      }
      else 
          mainlayout.setVisibility(LinearLayout.VISIBLE);
  
  
  }
  
  }
  </code></pre>