Introduction: Introduction to Android Programming!

About: I am a student from Amravati, Maharashtra, India. I love computer, android and electronics.

Hi guys, i am back with my V instructable on Android programming. I know very well that android is easy to learn and about 65% of people know how to program for android. But this instructable for those 35% :D. If you have any ideas, opinions or anything related to this ible, please comment it in the comment section.

In my dad's college there is gathering in which a two day workshop of android programming taken place. It is only for the college students but I requested and I got a chance to learn the android programming! I enjoyed very much. They've teached me four programs but here I am only teaching you one. Other three are advanced and I am going to describe that three programs in my next ibles. Okay, enough talk, let's make it.

Step 1: Downloading.

Requirements:

1. You need the java JDK, because we do 90% of coding in Java, 5% in XML and 5% in C. Link: http://www.oracle.com/technetwork/java/javase/downloads/index.html

2.You need ADT (Android Development Toolkit) in which we code, it is made up of eclipse. Link: http://developer.android.com/sdk/index.html

After downloading, extract it and install it.

Step 2: Preparing Eclipse(ADT)

Now after installing open Eclipse(ADT). It will ask you to make a workspace. Give it a desired name then you will see the eclipse window. Workspace is a project bundle in which our projects are saved. Now go to NEW-Android Application Project. As you see in the first image it will ask you to enter Application name. Enter the name of project as "button" because our first project is Button. After typing, click finish and you will get the window like in the second image.

Step 3: Coding Part

<em>Code:</em>

package com.example.button;
 
 import android.os.Bundle;
 import android.app.Activity;
 import android.view.Menu;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.Toast;
 
 public class MainActivity extends Activity implements OnClickListener {
 
 Button a;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 a=(Button)findViewById(R.id.button1);
 a.setOnClickListener(this);
 }
 
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
 // Inflate the menu; this adds items to the action bar if it is present.
 getMenuInflater().inflate(R.menu.activity_main, menu);
 return true;
 }
 
 @Override
 public void onClick(View arg0) {
 // TODO Auto-generated method stub
 Toast.makeText(this, "Here I am writing on instructables.", 5000).show();
 }
 
 }  

You can copy-paste this code or write it yourself. But remember, writing it helps you to learn the language. If you have any questions, you can ask me in the comment section.

So here's the explanation:

As you can see, in the first line, it shows package which we've entered earlier in the second step. Everything with import is the widgets we want to import in the project. The public class shows in which class we are working with. Button a is the variable we have set on the button we have created earlier.

The starting three lines of FirstOverride is by default in our project and it is for making the layout of our project. The fourth line of First Override shows that we are registering our variable a to the widget Button 1. The fifth line shows that we want to do something when Click on our Button.

The Center Override is not really worth and eve I don't know what it is :D :P.

The last Override is the main, because it shows which message we want to show on our screen. The Toast is the method for showing our message. You can think it like print in C language. So, what it is happening over there is, the first word of bracket this is we are telling Android to work on the Button. at the center, we are writing our message which we want to show. You can write anything in the double quotes in the Toast section. Like, I've written "Here I am writing on instructables.". The 5000 is the milliseconds of exact time we want to show this message. They are milliseconds so if we convert it to seconds it will be 5 seconds. You can vary the time and can experiment with it. At last, you can see the show() which is very important to show our message on the screen.

Don't hesitate to ask me anything in the comment section or you can also PM me. Also, don't forget the semicolon at every end of line because it shows our language that which line ends where.

Step 4: AVD(Emulator)

Ok to emulate anything in eclipse we have to make an AVD. AVD means Android Virtual Device. It is a virtual android device on which we can emulate our apps. Go to Window and then in AVD Manager, click new write a name and and Target then click create AVD. In a few minutes our AVD will be created. Go to run and click run. Now your application is emulating......

When the application opens click on the button and it will show your desired message! Congratulations you have created your very first ANDROID APPLICATION.

If you have any questions you can ask me in the comment box and below are some links from which you can learn the advanced knowledge of Android.

http:/www.thenewboston.org
http://developer.android.com/training/index.html
http://www.gadgetprogrammer.wordpress.com

Any help will be appreciated and don't forget to vote for me in Make-to-Learn Youth Contest.

Bye and have a good Day.
And Sorry for my bad English :D


Make-to-Learn Youth Contest

Participated in the
Make-to-Learn Youth Contest