first_app_2

A hello-world programming in android

Hi friends this is a hello world programming, before start this you must have to read how to create first application in eclipse

if already read you may continue. After creation of Android application you will get a java file in src folder here named "MainActivity.java" under the package "com.androidfromhome.helloworld" and get a xml file in layout folder under the res folder here named "activity_main.xml" . Now open "activity_main.xml"  drag and drop a TextView from the palette to xml as shown in image.

first_application

 

Now Drag TextView to xml file and rename id after "@+id/" from properties window as show in image. Now go to the java file and initialize the TextView object.

first_app_2


MainActivity.java  full code


package com.androidfromhome.helloworld;

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

public class MainActivity extends Activity {

private TextView tv_text;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv_text=(TextView)findViewById(R.id.tv_text);

tv_text.setText("This is my first android application");
}
}


activity_main.xml  full code


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.androidfromhome.helloworld.MainActivity" >

<TextView
android:id="@+id/tv_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />

</LinearLayout>


Now Run Project to get result.This  result show in android emulator.

first-app3

 

Download Full Code

Leave a Reply

Your email address will not be published. Required fields are marked *

Get Widget