Hi,I am new to android development and I have made this using help
from a website.
Please Help,Thanks.
The XML files dont have any errors,Here is my Main java code:
package com.CFConverter;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class CFConverter extends Activity {
    /** Called when the activity is first created. */
        private EditText text;

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

        text = (EditText) findViewById(R.id.EditText01);



    }

    //This Handler is called when we click the button01.

    public void myClickHandler(View view)               //passing the current 
view
    {


        if(view.getId()== R.id.Button01)
        {

                RadioButton celsiusButton =
(RadioButton)findViewById(R.id.RadioButton01);
                RadioButton farhrenheitButton =
(RadioButton)findViewById(R.id.RadioButton02);
                if(text.getText().length()==0)
                {
                        Toast.makeText(this, "Please Enter a Valid Number",
Toast.LENGTH_LONG);
                        return;
                }
                float inputValue = Float.parseFloat(text.getText().toString());
                if(celsiusButton.isChecked())
                {
                        text.setText(String.valueOf(convertCToF(inputValue)));  
//
calling function to convert
                }
                else
                {
                        text.setText(String.valueOf(convertFToC(inputValue)));
                }
                return;
        }


    }


    private float convertCToF(float fahrenheit)
    {
        return ((fahrenheit - 32) * 5 / 9);
    }
    private float convertFToC(float celsius)
    {
        return ((celsius * 9) / 5) + 32;
    }



}


I was searching for the error on the internet,I read somewhere that
when you use findViewbyId(),you need to use setContentView().But I
dont know how to use it. :(

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en

Reply via email to