Android: How to do an if-else statement depending on user input by spinner & radio button
<p>I am trying to write an if-else statement depending on what the user clicks. This is my main.xml:  </p>

<pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
&gt;

&lt;TextView 
android:text="Food #1:" 
android:textSize="20dp" 
android:textStyle="bold"
android:layout_height="wrap_content" 
android:id="@+id/txt_comparing" 
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"&gt;
&lt;/TextView&gt;

&lt;Spinner 
android:layout_height="wrap_content" 
android:layout_width="match_parent"
android:layout_below="@+id/txt_comparing"
android:id="@+id/spn_1"&gt;
&lt;/Spinner&gt;

    &lt;RadioGroup
android:id="@+id/canteen1"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/spn_1" &gt;

&lt;RadioButton
    android:id="@+id/option_0"
    android:text="ITAS  "/&gt;
&lt;RadioButton
    android:id="@+id/option_1"
    android:text="Design "/&gt;
&lt;RadioButton
    android:id="@+id/option_2"
    android:text="Engineering "/&gt;

&lt;/RadioGroup&gt;

&lt;TextView 
android:text="Food #2:" 
android:textSize="20dp" 
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:layout_below="@+id/canteen1"
android:layout_height="wrap_content" 
android:id="@+id/txt_and" 
android:layout_width="wrap_content"&gt;
&lt;/TextView&gt;

&lt;Spinner 
android:layout_height="wrap_content" 
android:layout_width="match_parent" 
android:layout_below="@+id/txt_and"
android:id="@+id/spn_2"&gt;
&lt;/Spinner&gt;

&lt;RadioGroup
android:id="@+id/canteen2"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/spn_2" &gt;

&lt;RadioButton
    android:id="@+id/option1_0"
    android:text="ITAS  "/&gt;
&lt;RadioButton
    android:id="@+id/option1_1"
    android:text="Design "/&gt;
&lt;RadioButton
    android:id="@+id/option1_2"
    android:text="Engineering "/&gt;

&lt;/RadioGroup&gt;

&lt;Button 
android:id="@+id/btn_compare" 
android:text="   Compare   " 
android:textStyle="bold"
android:layout_alignParentBottom="true" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content"
android:layout_alignParentRight="true"&gt;&gt;
&lt;/Button&gt;

&lt;Button 
android:text="  Clear   " 
android:layout_height="wrap_content" 
android:id="@+id/clear" 
android:layout_toLeftOf="@+id/btn_compare" 
android:layout_alignTop="@+id/btn_compare" 
android:layout_alignBottom="@+id/btn_compare" 
android:layout_width="wrap_content"&gt;
&lt;/Button&gt;
</code></pre>

<p>In my main java class, how do I create an if-else statement depending on what the user clicks? I have tried and researched many times but did not get the answer. </p>

<p>Thank you in advance!</p>
