When I attempt to change the text of the textbox it does not seem to
change and I cant figure out why. Here is my code:

package com.android.theperfecttip;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class The_Perfect_Tip extends Activity
{
        private EditText myBillAmt;
        private EditText myPrecentage;
        private TextView myAns;
        private Button myCalcButton;


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

                myBillAmt = ((EditText)findViewById(R.id.BillAmt));
        myPrecentage = ((EditText)findViewById(R.id.Precentage));
        myAns = ((TextView)findViewById(R.id.Ans));
        myCalcButton = ((Button)findViewById(R.id.CalculateBTN));
                double billNum = 
Double.parseDouble(myBillAmt.getText().toString());
                double preNum = 
Double.parseDouble(myPrecentage.getText().toString
());

                myAns.setText(""+calcTip(billNum,preNum));




    }

    public double calcTip(double billAmt,double prec)
    {
                try
                {
                        return (prec / 100) * billAmt;

                }
                catch(NullPointerException ex)
                {
                        Log.e("Excep:", "Null Pointer Exception");
                }
                catch(NumberFormatException ex)
                {
                        Log.e("Excep:", "Number Format Exception");
                }

                return -1;
    }
}


And here is the XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:alwaysDrawnWithCache="true">



    <TextView  android:id="@+id/BillAmtLBL"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Bill Amount"/>

    <EditText  android:id="@+id/BillAmt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0"/>



    <TextView  android:id="@+id/PrecentageLBL"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Precentage"
                />
    <EditText  android:id="@+id/Precentage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0"
                />


    <TextView  android:id="@+id/AnsLBL"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "Tip Amount"
            />
    <TextView  android:id="@+id/Ans"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "0"
            />

    <Button android:id = "@+id/CalculateBTN"
                android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text = "Calculate"
                />




</LinearLayout>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to