Develop Your First Android Application

We have Started From A Formal Description Of Android Application Development ..Then After We Had Learned About How To Configure Your System With Eclipse To Develop Your Android Apps..Then We Learned About How To Setup Android Virtual Device To Test Our Android Applications..

If You Didn't Read My Last Articles On these..Its Highly Recommended To Go Through That Articles..

Anyways So finally we are now ready to build our first android app. usually you start with  “hello world” program as your first program in any programming language but here let’s start with something new and a small app that uses a button which when clicked shows a message . Here you are going to learn how to use button, edit text and give background to your app in xml file. Before you start developing this app its necessary to know about the project structure.

Here is how a project structure tree looks when you create an Android project.

The brief description of important files/folders in the Android project structure is as follows

The src folder contains the Java source code files of your application organized into packages. You can have more than one package in your Android application. Its always a good practice to break the source code of your application into different packages based on its core functionality.  All the source files of your Activities, Services etc. Goes into this folder. In the above screen, you can see the source file of the Activity that we created for our project.

The files in the gen folder are automatically generated by the ADT. Here the file contains reference/index to all the resources in the res we use in our program. Each time we add a new resource to the project, ADT will automatically regenerate the file containing reference to the newly added resource. You should not edit the contents of file manually or otherwise your application may not compile.

/ANDROID <version number>
This folder is also called Android target library in Android project structure. The version number will be same as the build target version that we choose while creating a new project. The android.jar file contains all the essential libraries required for our program.

The assets folder is used to store raw asset files. You can keep any raw data in the assets folder and there’s an asset manager in Android to read the data stored in the folder. The raw data can be anything such as audio, video, images etc. On important point about assets folder is that the data stored in this folder can’t be referenced by an ID. To access a data in this folder, we have to work with bits and bytes.

/bin folder is where our compiled application files go. When we successfully compile an application, this folder will contain java class files, dex files which are executable under Dalvik virtual machine, apk archives etc.

Res folder is where we store all our external resources for our applications such as images, layout XML files, strings, animations, audio files etc.

Sub folders:
This folder contains the bitmap file to be used in the program. There are three different folders to store drawables. They are drawable-ldpi, drawable-mdpi, and drawable-hdpi. The folders are to provide alternative image resources to specific screen configurations. Ldpi, mdpi & hdpi stands for low density, medium density & high density screens respectively. The resources for each screen resolutions are stored in respective folders and the android system will choose it according to the pixel density of the device.

An XML file that defines the User Interface goes in this folder.

XML files that define simple values such as strings, arrays, integers, dimensions, colors, styles etc. are placed in this folder.

XML files that define menus in your application go in this folder

Android Manifest file

AndroidManifest.xml is one of the most important file in the Android project structure. It contains all the information about your application. When an application is launched, the first file the system seeks is the Android Manifest file. It actually works as a road map of your application, for the system.
The Android Manifest file contains information about:
  • Components of your application such as Activities, services etc.
  • User permissions required
  • Minimum level of Android API required

Finally done with lots of reading of Project Structure Tree it’s time to try out your first app.

Step 1: Go to file -> New -> project->Expand Android And Select Android Application Project

Step 2- Choose the lowest version API level in “minimum Required SDK” if you installed any lower version below API 16 because an app build on lower version API always supported by their successive higher version.
Remember here you can only deploy your app on Android 4.1 as you set the target so.

Step 3- After entering all the details as above you can see the next screen in which you can change the background, foreground color and image etc only if you want and click next.

Step 4- Here you can change the activity name which is going to display in your tiltle of your app bydefault it displays MainActivity but I changed it to the app name i.e., SampleAppActivity (naming convention is same as used in java) then click finish .

Its going to create a SampleAppActivity java file ,activity_sample_app xml file and other folders and files which you can check out in the package explorer the screen shot of which is already described in project tree structure.
Here is how your SampleAppActivity java file bydefault looks –

The basic unit of an Android application is an Activity. An Activity displays the user interface of your application, which may contain widgets like buttons, labels, text boxes, etc. Typically, you define your UI using an XML file .For example, the activity_sample_app xml.xml file located in the res/layout folder, which may look like this (bydefault) –

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
    android:layout_height="match_parent" >

        tools:context=".MainActivity" />


When you run the following code you can get to see the following screen on your emulator

Now in order to develop the app as required we need to edit these two files. Just edit as explained below:
Switch back to activity_sample_app xml file and edit as follows or simply copy the below code.
1. <?xml version="1.0" encoding="utf-8"?>
2. <RelativeLayout
3. xmlns:android=""
4. xmlns:tools=""
5. android:layout_width="match_parent"
6. android:layout_height="match_parent"
7. android:background="@drawable/image" >
9.    <TextView
10.    android:id="@+id/textView1"
11.    android:layout_width="wrap_content"
12.    android:layout_height="wrap_content"
13.    android:layout_alignParentLeft="true"
14.    android:layout_centerVertical="true"
15.    android:gravity="left"
16.    android:padding="@dimen/padding_medium"
17.    android:text="@string/hello_friends"
18.    android:textColor="@color/turquoise"
19.    android:textSize="35dp"
20.    android:textStyle="italic"
21.    android:typeface="serif" />
23.   <Button
24.    android:id="@+id/button1"
25.    android:layout_width="wrap_content"
26.    android:layout_height="wrap_content"
27.    android:layout_alignParentBottom="true"
28.    android:layout_alignParentLeft="true"
29.    android:layout_marginBottom="24dp"
30.    android:layout_marginLeft="18dp"
31.   android:background="@drawable/img"
 32.   android:text="@string/Go"
 33.   android:textStyle="italic" />
 35. </RelativeLayout>

Now open SampleAppActivity java file and add the code((the bold lines are added) or else copy the code.  (Don't Copy The Line Numbers With Code)
1. package com.LearnAndroid.SampleApp;

2. import;
3. import android.os.Bundle;
4. import android.view.View;
5. import android.view.View.OnClickListener;
6. import android.widget.Button;
7. import android.widget.Toast;

8. public class SampleAppActivity extends Activity {
9.   /** Called when the activity is first created. */
10.   @Override
11.    public void onCreate(Bundle savedInstanceState) {
12.        super.onCreate(savedInstanceState);
13.        setContentView(R.layout.activity_sample_app);
14.        Button button = (Button)      findViewById(;
15.        button.setOnClickListener(new  OnClickListener() {
16.           @Override
17.           public void onClick(View v) {
18.         Toast.makeText(SampleAppActivity.this, "Welcome To The World Of Android", Toast.LENGTH_SHORT).show();
19.           }
20.         });      
21.    }
22. }

That’s it you are now ready to run your first app. There are many ways to run the app. Just right click on the SampleApp in the package explorer you have created then Run As android application. Check out the screen shot below to run!

Please wait for a while it takes few minutes to deploy it in the emulator and when it loads voila! You have created your first app.


{ 84 comments... read them below or add one }

bcools said...

@drawable/ raising up error..image is file name or what..?from which image folder showld it be read from..?
and java file ( SampleAppActivity java ) at this line..findViewById(;
button1 is showing up an cannot be resolved or not in the filed..
i have run your code in ECLIPSE IDE...
is there still any thing to declare in strings.xml file..
i am a new learner..
plz let me know in detail..
expecting some more useful and excellent tutors from you as like this..

Anonymous said...

Hі thеre it's me, I am also visiting this site regularly, this web site is really pleasant and the users are in fact sharing nice thoughts.

Take a look at my blog post; Engagement Rings

Anonymous said...

What a video it is! Actually amazing and fastidious quality, please upload more movies having such good quality.

Here is my web site:
my web page -

Anonymous said...

What a lovely story! The story in this YouTube video that is posted here
is in fact a fastidious one with having fastidious picture quality.

Here is my weblog -

Anonymous said...

Hi there kids, you all have to watch hilarious videos, however keep in mind that first study then enjoyment okay.

Feel free to surf to my webpage website
Also see my webpage > website

Anonymous said...

Oh! Wow its in fact a humorous and jockey YouTube video posted at
this place. thanks for sharing it.

Feel free to surf to my web-site - website

Anonymous said...

Wow, incredible blog layout! How long have you been blogging for?

you made blogging look easy. The overall look of your site is magnificent, let alone the content!

Here is my site ::

Anonymous said...

Hi there! I could have sworn I've been to your blog before but after browsing through some of the posts I realized it's new to me.
Anyways, I'm definitely happy I found it and I'll
be book-marking it and checking back regularly!

Feel free to surf to my web-site: website
My web page:

Anonymous said...

What’s up I am from Australia, this time I am viewing this
cooking related video at this site, I am genuinely happy and learning more from it.

Thanks for sharing.

Feel free to visit my site ...

Anonymous said...

I usually don’t post in Blogs but your blog
forced me to, amazing work.. beautiful …

Feel free to visit my homepage ...

Anonymous said...

Pretty section of content. I simply stumbled upon your web site and in
accession capital to say that I acquire in fact enjoyed account your blog posts.
Any way I will be subscribing for your augment or even I success you access consistently fast.

my blog post
My web site ::

Anonymous said...

When someone writes an piece of writing he/she
retains the thought of a user in his/her brain that how a user can know it.
Therefore that’s why this piece of writing
is outstdanding. Thanks!

my web site;

Anonymous said...

Wow, thanks a bunch m8

My homepage
My website -

Anonymous said...

Hi mates, how is the whole thing, and what you want to say about this post, in my
view its really awesome for me.

My web page ...
my page -

Anonymous said...

That’s Too nice, when it comes in india hope it can make a Rocking place for
youngster.. hope that come true.

Here is my web site ...

Anonymous said...

I know this website gives quality based posts and other material, is there any other website which presents these data in quality?

Here is my web site;

Anonymous said...

I have study much concerning without charge blogging web pages, but
I have no clear idea about that, can any one advise
me which one is finest in favor of free blogging and site-building?

Check out my weblog website
Also see my web site: website

Anonymous said...

What’s up, for Search engine optimization genuine contents are actually needed,
if you only make a copy and paste then you can not ranked in search engines.

my web blog -

Anonymous said...

Hi there i am kavin, its my first occasion to commenting anyplace, when
i read this post i thought i could also make comment due to this sensible post.

My weblog:

Anonymous said...

Hi there Dear, are yоu really visiting thіs website
on a гegulaг baѕis, if so afterwаrd you wіll аbsolutely obtain nice experience.

Visit my pagе Engagement Rings
My website - Engagement Rings

Anonymous said...

I've been exploring for a bit for any high-quality articles or blog posts on this kind of area . Exploring in Yahoo I at last stumbled upon this site. Studying this info So i am happy to express that I've an inсгedibly gooԁ uncаnny feеlіng I discoveгed just what I needеd.
I such a lоt withοut a doubt will make surе to don?
t ρut out of your mind this website and gіνe it a looκ regularly.

Hаve a look at my web blog ... instant cash
My web site > instant cash

Anonymous said...

I got good info from your blog

Here is my page

Anonymous said...

It’s an remarkable article in support of all the web visitors; they will take advantage from it I am sure.

Also visit my web page website
Also see my site - website

Anonymous said...

All right this YouTube video is much improved than
last one, this one has fastidious picture feature as well as audio.

Here is my webpage - website
My webpage ::

Anonymous said...

:O So mush Info :O … THis Is he MOst AMAzing SIte DUDe…

Feel free to surf to my web blog -
my website - website

Anonymous said...

Wow! Thank you! I always wanted to write in my site
something like that. Can I take part of your post to my blog?

Here is my blog post ::
Also see my website - website

Anonymous said...

Thanks in support of sharing such a pleasant
opinion, piece of writing is fastidious, thats why i have read it fully

My webpage:

Anonymous said...

Wow! Thank you! I always wanted to write in my
site something like that. Can I take part of your post to my blog?

Visit my webpage website

Anonymous said...

Wow, this article is pleasant, my younger sister is analyzing these kinds of things, so
I am going to tell her.

My site ::

Anonymous said...

I all the time used to read piece of writing in news papers but now as
I am a user of internet therefore from now I am
using net for articles or reviews, thanks to web.

My site: website

Anonymous said...

This wеbsіte certainlу has all of the info I wаnted concеrning this subϳect anԁ diԁn't know who to ask.

Here is my website - same day payday loans
my website > same day payday loans

Anonymous said...

ohhh nice info

Also visit my weblog ::

Anonymous said...

ohhh nice info

Here is my homepage ::

Anonymous said...

I think a visualized display can be better then just a straightforward text, if stuff
are defined in graphics one can without difficulty be familiar with these.

Feel free to surf to my weblog: website
My page >

Anonymous said...

I am keen of learning Flash, is there any piece of writing related to Flash,
if okay, then please post it, thanks.

Here is my webpage ...

Anonymous said...

Hi there, it’s understandable piece of writing along with this YouTube video;
I can’t imagine that one can not understand this straightforward piece
of writing having with video demo.

Look into my web site:
Also see my site >

Anonymous said...

I got this website from my buddy who told me
concerning this web page and at the moment this time I
am browsing this web site and reading very informative articles
at this place.

My blog:

Anonymous said...

Hurrah, what a quality it is! Since mostly YouTube video tutorials have no pleasant feature, but this is in fact a fastidious quality video.

Also visit my blog -
my site >

Anonymous said...

he blog was how do i say it… relevant, finally something that helped me.

Here is my homepage ...

Anonymous said...

he blog was how do i say it… relevant, finally something that helped me.

Also visit my homepage -

Anonymous said...

Hurrah! Its also pleasant post about JavaScript, I am in fact keen of learning JavaScript.
thanks admin

My webpage -
Also see my webpage -

Anonymous said...

YouTube contains not only comic and humorous video tutorials but also it carries learning
related videos.

Here is my web blog ... website

Anonymous said...

Yes I am also in look for of Flash tutorials, as I would like to learn more on
the topic of flash, so if you have please post it here.

Here is my webpage -

Anonymous said...

What is captcha code?, pls provide me captcha code codes or plugin, Thanks in

Also visit my blog -

Anonymous said...

I usually don’t post in Blogs but your blog forced me to, amazing work.
. beautiful …

Also visit my web site

Anonymous said...

This article regarding SEO presents clear thought for
new SEO viewers that how to do SEO, so keep it up.
Fastidious work

Review my web blog
Also see my web page >

Anonymous said...

Hi there, I read your blogs on a regular basis. Your humoristic
style is witty, keep it up!

My website ::

Anonymous said...

The bowflex treadclimber is really a lot cheaper in comparison to other kind of gym

Here is my website website

Anonymous said...

Why visitors still make use of to read news papers when in this technological world everything is accessible on net?

Review my web site -

Anonymous said...

Wow, good YouTube video about how to install virtual directory, I totally got it.

Thanks keep it up.

Visit my blog

Anonymous said...

Wonderful, what a blog it is! This webpage provides useful data to us, keep it up.

Look at my site;

Anonymous said...

What’s up friend, what a quality is! For this
YouTube video, I am in fact pleassant, because I have never seen pleasant quality YouTube video before,

Here is my blog :: website

Anonymous said...

What’s up Jackson, if you are a new web user afterward you must visit
all the time this web page and read the updated posts at at this place.

my blog post -

Anonymous said...

Hi , I do believe this is an excellent blog. I stumbled upon it on Yahoo , i will come back once again.
Money and freedom is the best way to change, may you be
rich and help other people.

Check out my blog post;

Anonymous said...

Pretty! This was a really wonderful post.
Thank you for your provided information.

Here is my webpage ...

Anonymous said...

Hi there i am kavin, its my first occasion to commenting anyplace, when i read this post i thought i could also make comment due to
this sensible post.

my site :: website
Also see my page > website

Anonymous said...

Hello. Great job. I did not expect this on a Wednesday.

This is a great story. Thanks!

Also visit my web site:
my site -

Anonymous said...

Hi there, I read your blogs on a regular basis.
Your humoristic style is witty, keep it up!

my webpage;
my web site :: website

Anonymous said...

Hi there to all, I am also genuinely keen of learning Personal home pages programming,
except I am new one, I forever used to examine articles
related to PHP programming.

Feel free to surf to my blog;
My web site > website

Anonymous said...

When I saw this web site having amazing featured
YouTube videos, I decided to watch out these all videos.

My site -
My site: website

Anonymous said...

I keep listening to the news speak about getting free
online grant applications so I have been looking around for the best site to get one.

Here is my website ::

Anonymous said...

I am John, how are you everybody? This article posted at this
website is really good.
my web page: website

Anonymous said...

A number of viewers are keen to watch comic video clips, but I like to watch terrible videos on YouTube.

Feel free to surf to my website:
my page:

Anonymous said...

Keep working ,great job!

Feel free to surf to my web blog

Anonymous said...

To start earning money with your blog, initially use Google Adsense but gradually as your traffic increases, keep adding more and more
money making programs to your site.

my web blog
My webpage > website

Anonymous said...

Hello! I could have sworn I’ve been to this blog before but after
browsing through some of the post I realized it’s new to me.
Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

my site ...

Anonymous said...

When I saw this web site having amazing featured YouTube
videos, I decided to watch out these all videos.

Feel free to visit my website ...

Anonymous said...

This blog is definitely rather handy since I’m at the moment
creating an internet floral website - although I am only starting
out therefore it’s really fairly small, nothing like this site.
Can link to a few of the posts here as they are quite. Thanks much.
Zoey Olsen

Feel free to surf to my homepage

Anonymous said...

Hi, is it rite to simply study from publications not to pay
a quick visit web for latest updates, what you say guys?

my web site -
Also see my website > website

Anonymous said...

As a Newbie, I am always searching online for articles that can help me.
Thank you

Look at my webpage;
My site >

Anonymous said...

My partner and I absolutely love your blog and find most of your post's to be what precisely I'm
looking for. Would you offer guest writers to write content for you personally?
I wouldn't mind creating a post or elaborating on many of the subjects you write in relation to here. Again, awesome web site!

my website: Isabelle Flor

Anonymous said...

Hey there just wanted to give you a quick heads up.

The text in your article seem to be running off the screen in Internet explorer.

I'm not sure if this is a format issue or something to do with web browser compatibility but I figured I'd post to let you know.
The layout look great though! Hope you get the issue
fixed soon. Thanks

Also visit my web page :: Ashley Stephan
Also see my page: Norris Samuel

Anonymous said...

Great article, just what Ι was lοoking for.

Fеel free to viѕit mу web-ѕite small loans
My site > small loans

Anonymous said...

What's up, this weekend is pleasant designed for me, because this point in time i am reading this impressive educational post here at my residence.

Feel free to visit my web-site plan group cruise

Anonymous said...

If you would like to increase your know-how only
keep visiting this website and be updated with the most up-to-date gossip posted here.

my web page :: best all inclusive vacations

Anonymous said...

Ѕimрly wish tο saу your artіclе
іs as amazing. The clarity tο your
put up іs just gгеat аnԁ i can aѕsume you are a prоfеѕѕiоnаl in thiѕ
subject. Fine tоgethеr wіth your permіѕsion lеt mе to tаke hold of your feed to κеep
up to date with аpproachіng post. Thank you οne million and pleasе
κeeр uρ thе enjoyablе work.

Also visit my page ... payday loans

Anonymous said...

Very energetic blog, I enjoyed that a lot. Will there be
a part 2?

Look at my web blog - clear

Anonymous said...

I visited multiple ωebsites but the аudio quality for auԁio
songs exiѕting at this wеbsite
is actually ѕuperb.

my site - raspberry ketone uk

Anonymous said...

Great blog here! Also your ωeb site quіte
a bit up fаѕt! Whаt hoѕt arе you
thе usage of? Cаn I аm getting
your affiliate link for your host? I wіѕh my ωeb sіtе lοaded up
as quickly аs yοurs lοl

Alsо visit mу homepagе :: payday loans

Anonymous said...

Ѕpot on with this ωгitе-uρ, I absolutely fеel this web site needs muсh mοre аttention.
I'll probably be back again to read more, thanks for the info!

Feel free to visit my webpage: payday loans

Anonymous said...

Greetings! Verу useful advicе іn this particular post!
It is thе littlе changes thаt produсe thе greаteѕt сhanges.
Thanks for sharing!

Αlso ѵisit my ρage; Vistaprint Coupon

Anonymous said...

Incredible points. Solid arguments. Keep up the great spirit.
ageless male - ageless male - ageless male

Feel free to surf to my web page ... does ageless male enhancement work

TechloSOFT said...

nyc I hav created it using websites for creating app
Now ill try this
My blog is

Blogger said...

eToro is the ultimate forex broker for novice and full-time traders.

Post a Comment