title: converter with 2 spinner
body: <p>i need your help, this really driving me crazy and i really cant find the solution for it so what i want to create is a converter application for android here's my codes</p>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" &gt;
  
  &lt;EditText
      android:id="@+id/input"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ems="10"
      android:hint="Input Number Here"
      android:inputType="number" /&gt;
  
  &lt;Spinner
      android:id="@+id/spinner1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" /&gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Converts to:"
      android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
  &lt;Spinner
      android:id="@+id/spinner2"
      android:layout_width="103dp"
      android:layout_height="wrap_content" /&gt;
  
  &lt;Button
      android:id="@+id/btnSubmit"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Convert" /&gt;
  
  &lt;EditText
      android:id="@+id/output"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ems="10"
      android:inputType="number" &gt;
  
      &lt;requestFocus /&gt;
  &lt;/EditText&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>    package com.example.test;
  
  import java.util.ArrayList;
  import java.util.List;
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.AdapterView.OnItemSelectedListener;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.Spinner;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
  private Spinner spinner1, spinner2;
  private Button btnSubmit;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  addItemsOnSpinner2();
  addListenerOnButton();
  addListenerOnSpinnerItemSelection();
  }
  
  // add items into spinner dynamically
  public void addItemsOnSpinner2() {
  
  spinner1 = (Spinner) findViewById(R.id.spinner1);
  List&lt;String&gt; list1 = new ArrayList&lt;String&gt;();
  list1.add("Inches");
  list1.add("Feet");
  list1.add("Yard");
  list1.add("Miles");
  list1.add("Milimeter");
  list1.add("Centimeter");
  list1.add("Meter");
  list1.add("Kilometer");
  ArrayAdapter&lt;String&gt; dataAdapter1 = new ArrayAdapter&lt;String&gt;(this,
  android.R.layout.simple_spinner_item, list1);
  dataAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  spinner1.setAdapter(dataAdapter1); 
  
  
  spinner2 = (Spinner) findViewById(R.id.spinner2);
  List&lt;String&gt; list2 = new ArrayList&lt;String&gt;();
  list2.add("Inches");
  list2.add("Feet");
  list2.add("Yard");
  list2.add("Miles");
  list2.add("Milimeter");
  list2.add("Centimeter");
  list2.add("Meter");
  list2.add("Kilometer");
  ArrayAdapter&lt;String&gt; dataAdapter2 = new ArrayAdapter&lt;String&gt;(this,
  android.R.layout.simple_spinner_item, list2);
  dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  spinner2.setAdapter(dataAdapter2);
  }
  
  public void addListenerOnSpinnerItemSelection() {
  spinner1 = (Spinner) findViewById(R.id.spinner1);
  spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
  }
  
  // get the selected dropdown list value
  public void addListenerOnButton() {
  
  spinner1 = (Spinner) findViewById(R.id.spinner1);
  spinner2 = (Spinner) findViewById(R.id.spinner2);
  btnSubmit = (Button) findViewById(R.id.btnSubmit);
  
  btnSubmit.setOnClickListener(new OnClickListener() {
  
  
  if(selected1.equals("Inches"))
  {
  if (selected2.equals("Feet"))
  {
  //do calculation
  }
  else if (selected2.equals("unit"))
  {
  //do calculation
  }
  else if (selected2.equals("otherunit"))
  {
  //do calculation
  }
  else
  {
  //ERROR
  }
  }
  
  if (selected1.equals("m"))
  {
  if (selected2.equals("Yard"))
  {
  //do calculation
  }
  else if (selected2.equals("unit"))
  {
  //do calculation
  }
  else if (selected2.equals("otherunit²"))
  {
  //do calculation
  }
  else
  {
  //ERROR
  }
  }
  //repeat for all the possible units
  
  } 
  
  public void onClick(View v) {
  
  Toast.makeText(MainActivity.this,
  "OnClickListener : " + 
  "\nSpinner 1 : "+ String.valueOf(spinner1.getSelectedItem()) + 
  "\nSpinner 2 : "+ String.valueOf(spinner2.getSelectedItem()),
  Toast.LENGTH_SHORT).show();
  }
  
  
  }
  </code></pre>