Correct output being displayed through EditText only after the button associated with has been being clicked twice
<p>I'm writing a small code to convert one amount of currency to another. 
The app accepts two values through EditText (configured to accept decimal numbers)- 1) Home or away currency (If one is filled, the field of the other is left blank) 2) The exchange rate. </p>

<p>Here is the code:</p>

<pre><code>package kk.currency;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class CurrencyActivity extends Activity {
    /** Called when the activity is first created. */

    EditText inpval1;
    EditText inpval2;
    EditText rate;

    int v1 = 0;
    int v2 = 0;
    int r = 0;

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

    public void btnclick(View view)  {
        try {
            inpval1 = (EditText)findViewById(R.id.away);
            v1 = Integer.parseInt(inpval1.getText().toString());

            inpval2 = (EditText)findViewById(R.id.home);
            v2 = Integer.parseInt(inpval2.getText().toString());

            rate = (EditText)findViewById(R.id.rate);
            r = Integer.parseInt(rate.getText().toString()); 
        }
        catch (Exception e) {
            Toast.makeText(this, "Empty field", Toast.LENGTH_SHORT).show();
        }
        finally {
            v1 = v2 * r;

            EditText destination = (EditText)findViewById(R.id.away);
            destination.setText(Integer.toString(v1));
        }
    }   
}
</code></pre>

<p>The problem is that upon clicking the button associated with "btnclick" the field which is left blank (and where the answer is supposed to be displayed) displays 0, no matter what input. But when clicked again the correct answer is displayed.</p>

<p>And if I put any value in the field which is supposed to be left blank, the correct value is displayed in the first go. </p>

<p>What could possibly be the problem?! </p>

<p>On removing 'finally' and placing it's content into 'try' I don't even get any response upon clicking of the button. </p>

<p>Also, the LogCat is is completely empty during the execution of the app. </p>

<p>Here is the layout of the app as someone had requested. </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;TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dip"
    android:layout_marginLeft="5dip"
    android:text="@string/away"
    android:textStyle="bold"
    android:textSize="20dip"
    android:textColor="#4199ae" /&gt;

&lt;EditText
    android:id="@+id/away"
    android:digits="0123456789."
    android:inputType="number"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:hint="@string/c1" /&gt;

&lt;TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dip"
    android:layout_marginLeft="5dip"
    android:text="@string/conv"
    android:textStyle="bold"
    android:textSize="20dip"
    android:textColor="#4199ae" /&gt;

&lt;EditText
    android:id="@+id/rate"
    android:digits="0123456789."
    android:inputType="number"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:hint="@string/rate" /&gt;

&lt;TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dip"
    android:layout_marginLeft="5dip"
    android:text="@string/home"
    android:textStyle="bold"
    android:textSize="20dip"
    android:textColor="#4199ae" /&gt;

&lt;EditText
    android:id="@+id/home"
    android:digits="0123456789."
    android:inputType="number"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dip"
    android:hint="@string/c2" /&gt;

&lt;Button
    android:id="@+id/but"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dip"
    android:text="@string/buttxt"
    android:onClick="btnclick" /&gt;
</code></pre>

<p></p>
