Start Coding

Now Lets get started coding our first app :



Remember this one ...

Now each program consists of executable classes (execution code ) called Activity

Since we are developing a simple application we will use only the main Activity that is created by default
This will be generally  the name of Application.

These are the methods in Activity Class :

  • onCreate()
  • onStart()
  • onRestart()
  • onResume()
  • onPause()
  • onStop()
  • onDestroy()
But you will only use onCreate() for now 
Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a Bundle containing the activity's previously frozen state, if there was one.



Now 
goto res-> layout -> main.xml      and double click it.


You will get something like this :


This is called the layout of your app. This is the user interface that will be shown on screen when you run your app on phone

On the left side you will have various elements which you just have to drag and drop on the layout. It automatically gets added.

Here you will right click it and "Edit ID".
Now give any ID to it.

For now what we are going to do is is right click on the "Hello world, First App Activity! "  TextBox

edit its ID to mybox


Now go back to activity.java file and add the following code  after setContentView(R.layout.main)  :

        TextView mybox=(TextView) findViewById(R.id.mybox);
        mybox.setText("I have created my own App");



Now run your program ( if prompted select android application )


Sooner your emulator will start and It will be running your program.
If you have a phone just connect it to PC and it might just run on it instead.

Unlock the phone in emulator by sliding lock 

The result will be like this :  



 Hooray you have just made your first app.

No comments:

Post a Comment