Using more than one Spinner in a calculation
<p>Ok, so I'm trying to create an activity that works out the area of a given space.</p>

<p>I want the user to be able to enter the dimension in either "ft" of "m". The answer is required to be given in meters at the end.</p>

<p>Right, now to the problem.</p>

<p>The below code works, the problem is that the program assumes that both num1 and num2 are both equal to what ever is selected in the last spinner used. So if you input 100 ft for num1 then 10m for num2 it gives the answer of 1000m, because you select the m unit last. It should be giving the answer of 92.9...</p>

<p>This has been a headache for the last few days...</p>

<p>Can anyone help me!?!</p>

<p>Thanks in advance
Will</p>

<pre><code>private OnClickListener myClickListener = new OnClickListener()
{
    public void onClick(View v) {
        try{

        a=Double.parseDouble(num1.getText().toString());
        b=Double.parseDouble(num2.getText().toString());}
        catch(Exception e)
        {
            if(num1.getText().length()==0)
            {
                num1.setError("please input width");
            }
            if(num2.getText().length()==0)
            {
                num2.setError("please input length");
            }

        }

        if (opselected=="ft" &amp;&amp; opselected1=="ft")
        {c=((a * 0.0929) * (b * 0.0929));tv1.setText(Double.toString(c));}
        else if (opselected=="m" &amp;&amp; opselected1=="m")
        {c=( a * b);tv1.setText(Double.toString(c));}
        else if (opselected=="m" &amp;&amp; opselected1=="ft")
        {c= (a * (b * 0.0929));tv1.setText(Double.toString(c));}
        else if (opselected=="ft" &amp;&amp; opselected1=="m")
        {c= ((a * 0.0929) * b);tv1.setText(Double.toString(c));}



        else {tv1.setText("select units");}
        //tv1 = (TextView)findViewById(R.id.TextView01);


    }
};
    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.car);

       tv1 = (TextView)findViewById(R.id.TextView01);


       button01 = (Button)findViewById(R.id.Button01);
       button01.setText("Display Air Volume");
       button01.setOnClickListener(myClickListener);



       num1 = (EditText)findViewById(R.id.EditText01);
       num2 = (EditText)findViewById(R.id.EditText02);



       spinOps = (Spinner)findViewById(R.id.Spinner01);
       ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(
         this, android.R.layout.simple_spinner_item, ops);
       adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
       spinOps.setAdapter(adapter);
       spinOps.setOnItemSelectedListener(this);

       spinOps1 = (Spinner)findViewById(R.id.Spinner02);
       ArrayAdapter&lt;String&gt; adapter1 = new ArrayAdapter&lt;String&gt;(
         this, android.R.layout.simple_spinner_item, ops1);
       adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
       spinOps1.setAdapter(adapter);
       spinOps1.setOnItemSelectedListener(this);

    }   
    public void onItemSelected (AdapterView&lt;?&gt; p,View v,int position,long id) {
        opselected=ops[position];
        opselected1=ops1[position];
        tv1.setText("");
    }
    public void onNothingSelected(AdapterView&lt;?&gt; p) { 
        tv1.setText(""); 
    }
</code></pre>
