Developing android applications


I have just published an application on the android marketplace, you can scan the bar code or click here to install it.  This application was created as a training exercise so is not very complicated.  The application will convert miles per gallon (imperial) to litres per 100kms.

The whole android development process is well documented on the internet and if you have java experience you are off to a flying start.  There is very little required to get started and the only cost is a $25 registration fee if you wish to publish on the android market (this is not required for developing).

I have used Linux and Windows to test the developers kit and it works fine on both.  It also runs on macs but I haven’t tested this personally.

Eclipse appears to be the most popular ide for developing android applications and is well supported with install guides and help for any typical problems you might encounter.  The other download required is the android developers kit (ADK) which is available from http://developer.android.com/sdk/index.html.

Here are a few locations with guides for installing Eclipse and the ADK –

http://androidforums.com/developer-101/2314-installing-eclipse-android-sdk-windows-xp.html or http://www.talkandroid.com/android-sdk-install-guide/

Here is a code snippet from my application, I will update this post as I develop the application further a learn more about this platform.

import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.RadioButton;

public class Litre2MPGActivity extends Activity {
	private Button btn;
	private TextView tv;
	private RadioButton r1;
	private EditText et;
	private double myValue;
	private NumberFormat myNumberFormat;

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

        btn = (Button) findViewById(R.id.button1);
        tv = (TextView) findViewById(R.id.textView1);
        r1 = (RadioButton) findViewById(R.id.radio0);
        et = (EditText) findViewById(R.id.editText1);
        myNumberFormat = new DecimalFormat("#,###.#");
        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	try
            	{
            	if (r1.isChecked()){
            		myValue = 282.5/Double.parseDouble(et.getText().toString());
            		tv.setText("your l/100 is " + myNumberFormat.format(myValue));
            	}
            	else {
            		myValue = 282.5/Double.parseDouble(et.getText().toString());
            		tv.setText("your mpg is " + myNumberFormat.format(myValue));
            	}  
            	}
            	catch (NumberFormatException e)
            	{
            	new AlertDialog.Builder(Litre2MPGActivity.this).setTitle("Error" )
            	.setMessage("Enter a number")
            	.setPositiveButton("OK", null).show();
            	}

            }
        });
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s