Android Hello World Example:
- Now we are going to write first android programming with Android Framework.
·
Before starting program, please make sure that
you have setup your Android Development environment properly. And one more thing you should have atleast
little bit knowledge on Eclipse IDE
Create Android Application: Steps
·
Select Android New Application wizard from the
wizard list. Now name the Application Name as HelloWorld using the wizard
window as follows:
·
Next, follow the instructions provided and keep
all other entries as default till the final step. Once your project is created successfully,
we will get the following project screen:
Click on Next button:
- for the first time keep it as default:
- click on next button:
- for the first time keep it as default:
- click on next button
-
- click on finish button
- see the project explorer:
-
-
- If you want to display "Good Morning" on the Emulator,
- go to values from the Explorer
- click on strings.xml file from values
-
- see the code of "strings.xml" file
- <?xml version="1.0" encoding="utf-8"?><resources><string name="app_name">demo</string><string name="action_settings">Settings</string><string name="hello_world">Hello world!</string></resources>
- and change the <string name="hello_world">Hello world!</string> string name and what ever you want to display:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">demo</string>
<string name="action_settings">Settings</string>
<string name="raj">Good Morning</string>
</resources>
- so now the code looks like this:
- Go to activity_main.xml from layout, and change the following line:
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
- Change it as the following code (see the Bold code below):
- now save the strings.xml and activity_main.xml file:
- now run the program by placing the mouse on project name
- see the emulator: it will take some time
- unlock the by dragging the lock icon:
once you unlock that screen will look like this:
- it will take some time(don't close)
- final out put we can see in the emulator: (like below)
No comments:
Post a Comment