title: length converter android studio
body: <p>I am trying to make a length converter app and my confusion is how do I get my work done to convert from one unit to another unit using two spinners and a calculate button? The issue I have is that I cannot figure out how to convert the unit in the drop down list from one spinner to another unit in the second spinner. I also need to display the answer after the user enters the number and picks the units from the list. </p>
  
  <p><strong>This is my layout file of my main activity</strong></p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
     &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/activity_main"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.example.unitconverter.MainActivity"&gt;
  
  &lt;Button
      android:text="WEIGHT"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:onClick=""
      android:layout_below="@+id/lengthButton"
      android:layout_alignRight="@+id/lengthButton"
      android:layout_alignEnd="@+id/lengthButton"
      android:id="@+id/weightButton"
      tools:ignore="HardcodedText" /&gt;
  
  &lt;Button
      android:text="LENGTH"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/lengthButton"
      android:layout_marginTop="164dp"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      tools:ignore="HardcodedText" /&gt;
  
  &lt;TextView
      android:text="Unit Converter"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="76dp"
      android:id="@+id/textView"
      android:textSize="36sp"
      android:textColor="@android:color/background_dark"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true" /&gt;
  
  &lt;Button
      android:text="VOLUME"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/volumeButton"
      tools:ignore="HardcodedText"
      android:layout_below="@+id/weightButton"
      android:layout_alignLeft="@+id/weightButton"
      android:layout_alignStart="@+id/weightButton" /&gt;
  
  &lt;Button
      android:text="TEMPERATURE"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/temperatureButton"
      tools:ignore="HardcodedText"
      android:layout_below="@+id/volumeButton"
      android:layout_centerHorizontal="true" /&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>This is the java portion of my main activity</strong></p>
  
  <pre><code>         public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
  
          Button lengthbtn = (Button) findViewById(R.id.lengthButton);
  
          lengthbtn.setOnClickListener(new OnClickListener(){
              public void onClick(View v){
                  startActivity(new Intent(MainActivity.this, lengthActivity.class));
              }
          });
  
          Button weightbtn = (Button) findViewById(R.id.weightButton);
  
          weightbtn.setOnClickListener(new OnClickListener(){
              public void onClick(View v){
                  startActivity(new Intent(MainActivity.this, weightActivity.class));
              }
          });
  
          Button volumebtn = (Button) findViewById(R.id.volumeButton);
  
          volumebtn.setOnClickListener(new OnClickListener(){
              public void onClick(View v){
                 startActivity(new Intent(MainActivity.this,volumeActivity.class));
              }
          });
  
          Button temperaturebtn = (Button) findViewById(R.id.temperatureButton);
  
          temperaturebtn.setOnClickListener(new OnClickListener(){
              public void onClick(View v){
                  startActivity(new Intent(MainActivity.this,temperatureActivity.class));
              }
          });
  
      }
  }
  </code></pre>
  
  <p><strong>This is my length layout file</strong> </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/activity_length"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.example.unitconverter.lengthActivity"&gt;
  
  &lt;Spinner
      android:layout_width="200dp"
      android:layout_height="wrap_content"
      android:layout_marginTop="20dp"
      android:id="@+id/lengthList2"
      android:textAlignment="center"
      android:layout_marginLeft="11dp"
      android:layout_marginStart="11dp"
      android:layout_below="@+id/convertToTextView"
      android:layout_alignLeft="@+id/convertToTextView"
      android:layout_alignStart="@+id/convertToTextView" /&gt;
  
  &lt;TextView
      android:text="Length Converter"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textAppearance="@style/TextAppearance.AppCompat.Display2"
      android:textSize="36sp"
      android:textAlignment="inherit"
      android:id="@+id/lengthTextView"
      android:layout_alignParentTop="true"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"
      android:layout_marginLeft="25dp"
      android:layout_marginStart="25dp" /&gt;
  
  &lt;Button
      android:text="Calculate"
      android:id="@+id/calculateButton"
      android:layout_width="100dp"
      android:layout_height="45dp"
      android:layout_marginTop="53dp"
      android:layout_below="@+id/lengthList2"
      android:layout_alignRight="@+id/lengthList2"
      android:layout_alignEnd="@+id/lengthList2"
      android:layout_marginRight="23dp"
      android:layout_marginEnd="23dp"
      android:textAlignment="center" /&gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/resultTextView"
      android:text="Result "
      android:textSize="20sp"
      android:layout_marginBottom="34dp"
      android:layout_alignParentBottom="true"
      android:layout_alignLeft="@+id/lengthList2"
      android:layout_alignStart="@+id/lengthList2" /&gt;
  
  &lt;TextView
      android:text="Convert to:"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textSize="24sp"
      android:layout_marginTop="114dp"
      android:id="@+id/convertToTextView"
      android:layout_below="@+id/convertEditText"
      android:layout_alignLeft="@+id/convertEditText"
      android:layout_alignStart="@+id/convertEditText" /&gt;
  
  &lt;EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:inputType="textPersonName"
      android:text="Convert from"
      android:ems="10"
      android:id="@+id/convertEditText"
      android:layout_below="@+id/lengthTextView"
      android:layout_alignLeft="@+id/lengthTextView"
      android:layout_alignStart="@+id/lengthTextView"
      android:layout_marginLeft="11dp"
      android:layout_marginStart="11dp"
      android:layout_marginTop="52dp" /&gt;
  
  &lt;Spinner
      android:layout_height="wrap_content"
      android:entries="@array/lengthList"
      android:id="@+id/lengthList"
      android:layout_width="200dp"
      android:layout_marginTop="13dp"
      android:layout_below="@+id/convertEditText"
      android:layout_centerHorizontal="true" /&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>This is what I have for my main activity length file. Can anyone please help me?</strong> </p>
  
  <pre><code>public class lengthActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate (saved Instance State);
          setContentView(R.layout.activity_length);
  
          final Spinner group = (Spinner)findViewById(R.id.lengthList);
          final Spinner group2 = (Spinner)findViewById(R.id.lengthList2);
  
          Button button = (Button)findViewById(R.id.calculateButton);
  
          button.setOnClickListener(new View.OnClickListener() {
              final TextView result = ((TextView) 
  
  
  
              @Override
              public void onClick(View v) {
  
  
  
              }
  </code></pre>