Android Tutorial : “Hello Android”

Goals to be meet in This Tutorial:

  • Talking about Activity and Application Layout in Android.
    ——————————-

Activity resembles a Module or form in C# for example which we will use it to make interactive application, Let’s create one we are going to call it “HelloAndroid”, every Activity class must extends form class Activity and Override Function OnCreate.

As we showed last time in First Tutorial creating a new Project will already create a class(extends Activity) with a template code which we will modify or change according to our needs.

Our Main Activity Class “HelloAndroid”  will look like this:

package com.example;

import android.app.Activity;
import android.os.Bundle;

public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); //Handles the Activity preview Layout and Properties.
}
}

Next Step is to Specify the Layout of our Application, so Choose Folder ‘res’ and then ‘layout’ then ‘main.xml’, this folder holds the basic layout and controls of our class which resembles here the GUI code for a Form and it’s controls.

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello”
/>
</LinearLayout>

TextView property name ‘android:text’ contains value “@string/hello” the @keyword then a name is used to refrence the application resources and word hello is predefined in ‘res’ → ‘values → strings.xml , we will go there and change text to “Hello World”.

<?xml version=”1.0″ encoding=”utf-8″?>
<resources>
<string name=”hello”>Hello World</string>
<string name=”app_name”>Tutorial Android</string>
</resources>

Refrences:

http://developer.android.com/reference/android/app/Activity.html

Ok, That’s all for now Hope it’s useful and feedback is welcomed :) .
Thanks for Reading and for your time.

About these ads

About ferasferas

Proud To Be Muslim
This entry was posted in Tools. Bookmark the permalink.

One Response to Android Tutorial : “Hello Android”

  1. Nice post. I learn something totally new and challenging on blogs I stumbleupon everyday.
    It’s always interesting to read through content from other authors and use a little something from other websites.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s