Wednesday, December 7, 2011

How to Create HelloAndroid or Your First Android Application

First thing you have to set up the Environment to run the Android application. If you don't done so far. you can follow this link to setup your Android SDK.
http://agileswaran.blogspot.com/2011/12/simple-and-easy-way-to-install-android.html

  •  Open eclipse
  •  After that go to File<New<Other




  • It's open another window then Select Android Folder<Android Project

  • Then Specify your project Name, Build Target and Application Info


  • After give all details click finish to create your Android project.
  • Open your src folder<java class
In first Example I explain about layout set by . XML class this is located under res<layout folder in your project.
So you can easily add buttons, textview, image, etc via XML layout.

import android.app.Activity;
import android.os.Bundle;
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}
}

Second Example,  I explain about layout set by programming.
Display the "Hello,Android" via programming. 

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
 /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView tv = new TextView(this);
    tv.setText("Hello, Android");
    setContentView(tv);
 }
}
Finally simply hit F11 to build and run the your project.


No comments:

Post a Comment