Tuesday, 15 July 2014

Android Hello World Application

Well on this time onwards we are moving to practical session for better understand. I am going to show you how to create the application in android using the eclipse IDE.In the beginning we will do the small application.
First we need to create the project in android to do that select file and right click that and select new, Android Application Project. At this stage one window will appear and you need to fill the project name and package name and click next, next and finish.
Now you can able to see the project that you created on the package explorer. Now you need to expand the project and you can able to see several folders with the java and xml coding.
In our first application we are going to create the hello world application for this you need to expand the src folder in the application which you created. Double click the MainActivity.java and on the you can able to see the following coding
Package com.example.p1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    @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;
    }
   
}
In the program android starts with the onCreate method and the class extends the Activity and it contain the bundle and its object. It also contain the setContentView which is used to extends the properties of android Xml file.You can able to get the xml file in the res,layout folder like activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />
</RelativeLayout>
Xml coding is used to provide the UI for your project.that's it you create the application to run this right click the project which you created and select runas,then select run configuration.
You need to create a run time environment for android, after selecting run-time configuration one new window will appear on that select the target machine. And select always pick the prompt device and once you did click apply and Ok that’s Congratulation you have been created an application in android.

No comments:

Post a Comment