Simple Hello World Program in Android
Step1: Open
Eclipse
Step2 :
Specify your Work Space
Step3: Now
Go to File => Project => Android Project =>Next
Step4: Give Some Project Name(Here I am Giving
HelloWorld)
Step5:
Choose Your Target SDK(Here I am Taking Android 4.0.3. You can choose any one 2.2 or 2.3 like that).
Step 6:
After choosing Target SDK,Click on NEXT.
It will ask Package name,activity
name(Class name).
For package you need to specify like
that (android.hello world or anyname.name).If you not specify “ . “, it will
show error.Here I am taking package “test.helloworld”.
Activity name(Class name) taking as a
“HelloWorldActivity”.
Step7: Open Negivator in Your eclipse(Window
=>Show View => Nevigator
Now See your Activity File, Layout file.
Step8: Open
all the files that I marked.
Go 2 main.xml. See Here we have
taken TextView that means output will show in text view. See bellow how it
would look like.
Step9:The
question will arises How it is showing
“Hello World,Hello World Activity”.
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
See here
android:text ,we are calling @string/hello. This means it calling to
string.xml(res/values).
Open
string.xml.
<string name="hello">Hello World,
HelloWorldActivity!</string>
<string name="app_name">HelloWorld</string>
Here
we are giving string name “hello” that is calling main.xml. So the output will
be “Hello
World, HelloWorldActivity!”.
Step10:
Xml is basically used for designing the
activity. Now this xml file will call in Java File.
Go To “HelloWorldActivity.java”
class(src/test/helloworld).
public class
HelloWorldActivity extends Activity
{
/** Called when the activity is first
created. */
@Override
public void onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
See here HelloWorldActivity class
extending Activity.For developing any mobile application we need to inherit the
methods from Activity.
Observe in “setContentView(R.layout.main);”, here it is
calling that xml file.
Step11: (EXECUTION)
It will take some time to load your
activity.
No XML content. Please add a root view or layout to your document
ReplyDeletehow to solve this error ??
Check in your Activity(HelloWorldActivity.java) file. setContentView(R.layout.main) will be there.
DeleteWhen You execute your project, you must Execute from your main java file or RightClick on Project name(Navigatore)=>Run As=> Android Application
main.xml file will look like bellow:
Deletetry to insert the google followers and fb like option in the blog to follow the blog regularly
ReplyDeleteThanks For Your Suggestion.......
DeleteI will Do It.
My facebook Page:
http://www.facebook.com/Android4Delopment