You want to create android apps and you are wondering where to start? Maybe you can get started making great applications and make some cold hard cash – I make no guarantees that you will be richer than you are now, therefore don’t sue me for saying you might make money! Let us get to it, shall we?

Here is what our final app will look like:

This might end up being the simplest application you will ever build if you choose to go further. As you can see, all we have is an input area to type our to do items and when you press the center button on the right side, the input area is cleared and the item is added to the list. Nothing very fancy but still good for a start.

Setting Up TheAndroid Development Tools

I am not going to assume anything here today except some java programming basics. That means you don’t have to worry about what you don’t have already. We will need several things before we start building our To Do List android app. I am going to guide you through downloading and installing the software needed. There are several options on how to get started and that implies that my way is not the only way.

Step 1 : Download and Install a Java Runtime Environment

If you don’t have a Java Runtime Environment already installed, you can easily download it from here – simply choose the right one for your operating system. Installation is straight-forward. We need it because we will be using the Eclipse IDE which requires Java to work.

Step 2 : Download Android SDK ADT Bundle.

I highly recommend downloading the SDK Bundle because it makes everything simple. You don’t have to worry about putting the pieces together and running into problems. You can find the bundle here and just to make it clear, here is how the page looks like:

While on the above page, click the download button and you will be on your way. I figured you might be asking yourself – “do I need to perform any configurations or setups?” That is why I want to share this other setup snapshot.

If the above image is not very clear, please click it. Basically, what you should do after the download is done is double click it to unzip. Please do not move any files away from the folder. Navigate to where eclipse is within that same folder that you just unzipped and launch it.

Note: Using Eclipse Plugin – If you already have Eclipse installed, you might prefer to install the Android tools without installing eclipse twice. If that is the case, please click installing android ADT on Eclipse to find the right instructions on how to setup your environment.

Setting up the To Do List App project on Eclipse

This To Do List app will be very simple. It will provide a user with an input area where one can type text and when they press the center button, the same text will be added to the list and neatly displayed on the view. It will also clear the input area for more items to be entered. Simple right? Are you excited about this? Using your eclipse click File -> New -> Android Application Project. You should see something like this:

Note: You might notice that Android Application Project is not visible the first time you create a similar project. In that case, do this: File -> New -> Other. From here, you will be able to locate Android Application Project under Android. At this point, I assume you have installed everything as explained above. Next follow the project wizard and fill up the properties like this:

Once again, please click the above image to zoom in. Basically, all you need to do is give your application a name and a package. For now, you can leave the rest as default. Click Next. Keep clicking Next until the end where you click Finish.

A project will be created with everything you need to get started. For now however, we will focus on two files: MainActivity.java and main.xml. You might be thinking, where the heck is main.xml? I only see layout_main.xml. Do not worry, I changed mine from layout_main.xml to main.xml to make it look better. You can leave yours the way it is or change it to whatever reasonable name you want – remember to edit in both res/layout/main.xml and MainActivity.java inside onCreate() method. In summary, we will be focusing on these two files today:

MainActivity.java

And main.xml

Please click the above images to look closer. Don’t worry, we will be coding both of them right now so that you can copy and paste if you wish to follow along and test for yourself.

Inside main.xml file

When you created your first android app project, several files were generated including main.xml and MainActivity.java – the activity that your application will use. It is a subclass of the Activity class. We will edit main.xml to add what our app needs : input area and a list view to display our to do items. Let us do it:

[xml]

< ?xml version="1.0" encoding="utf-8"?>



[/xml]

That is all we need for this file. Please remember to type RelativeLayout, EditText and ListView as I have written here as opposed to what you see in the above code. The syntax highlighter made everything lowercase which is not what it should be.

In the above main.xml, we are using @+id/myEditText and @+id/myListView so that we can reference them inside MainActivity.java. Let us take a look at this file now

It seems reasonable to use an ArrayList for our to do list right? We are going to do exactly that.

[java]

package com.simpledeveloper.todolist;

import java.util.ArrayList;

import android.os.Bundle;

import android.app.Activity;

import android.view.KeyEvent;

import android.view.View;

import android.view.View.OnKeyListener;

import android.widget.ArrayAdapter;

import android.widget.EditText;

import android.widget.ListView;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

final EditText myEditText = (EditText)findViewById(R.id.myEditText);

ListView myListView = (ListView)findViewById(R.id.myListView);

final ArrayList todoItems = new ArrayList lt;string>();

//create an array adapter to bind the array to list view

final ArrayAdapter lt;string> aa = new ArrayAdapter lt;string>(this,

android.R.layout.simple_list_item_1, todoItems);

/*bind the array adapter to the ListView */

myListView.setAdapter(aa);

myEditText.setOnKeyListener(new OnKeyListener(){

public boolean onKey(View v, int keyCode, KeyEvent event){

if (event.getAction() == KeyEvent.ACTION_DOWN){

if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER){

todoItems.add(0, myEditText.getText().toString());

aa.notifyDataSetChanged();

myEditText.setText(“”);

return true;

}

}

return false;

}

});

}

}

[/java]

Explanation of what just happened

Believe it or not, that is all we need for our simple to do list android app! We can now start making a few dollars – not really. Let me briefly explain to you what that code does. It is not as complicated as it might seem (especially if this is your first time).

Inside onCreate() method, we setContentView(R.layout.main) – basically saying, when this app is started, display the components inside main.xml which is located in the layout folder…see?

method, we setContentView(R.layout.main) – basically saying, when this app is started, display the components inside main.xml which is located in the layout folder…see? We then make references to the components we defined inside main.xml (myEditText and myListView). We use findViewById(R.id.myEditText, R.id.myListView) respectively. Remember the ids we created earlier inside main.xml? There you go.



As I stated a few minutes ago, it makes sense to use ArrayList to store our to do items. Our to do items will be strings and that is why our ArrayList will expect strings to be stored. If you know of another way, then try that. So we define it for later use.

In order for us to bind a ListView to an ArrayList, we use an ArrayAdapter. That is what we created above immediately after defining the ArrayList object. Don’t worry so much about understanding all of it at once – you can spend more time going through the documentation for more information. After defining an ArrayAdpter instance, we bind it to myListView using setAdapter() method.

using method. Finally, we need to enable users to type in some items. We will use an OnKeyListener which we add to EditText. This listens for a D-Pad Center Button click before adding the content of the EditText to the to do list array and notifying the ArrayAdapter of the change. We finally clear the EditText to create room for another item to be typed.

That, just so you know, is our simple to do list android app! You did it. You can now pat yourself and grab a beer or something that returns the same outcome. If you did everything correctly, click the run button on the editor to see your app working.

In summary and all honesty, we have just touched the surface of android development. This being so minimal however, is a good place to start your journey. Explore further. Do not stop here, in fact, add more features to this application and even publish it for others to download.

Thank you for your patience through this post. If you liked it, please consider sharing with your friends using the buttons below. Please remember to subscribe and tell me what you think through the comments – I would love to hear from you. Thank you once again and if you have any questions, you are free to ask. See you soon.

Perhaps it goes without saying that you MUST pay a visit to the Android Documentations if you are learning to create android apps.