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.
My code is:
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<String>data1=new ArrayList<String>();
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<String>adapter=new ArrayAdapter<String>(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);
}
}