Thursday, 31 March 2011

Starting Android

After Downloading of android SDK (If not then Click here )and Installing  ADT pluggin for eclipse(If not then  Click here ) now we write our frist android app. if preference not to android then  start eclipse then click on Windows --> Preference --> Android  after that Bowes SDK location .





After that Update SDK click Windows -->Android SDK and AVD manager --> Available package then install Android Repository SDK platform like  SDK Platform  Android 2.2.3 API 10 


 It's time to create an Virtual Device in Android SDK and AVD manager go to Virtual device Pane and Click on Add new pop-up  open enter name of AVD set Target give SD card size in MB Change skin default to HVGA Create AVD.
Now we have new AVD select it and Start it .
Close Android SDK and AVD manager.
 We are ready for first application , click on File -->New --> Other/Android Project

Specify project name ,target,application name,pkg name, check Create Activity give its name Min sdk suppose 10 etc. then Finish Your first project almost ready..

Open your Activity class which looks like ..


package pkg_name;

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

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

here Class which extends Activity (android.app.Activity) ,Activity provide instruction to user it handle all UI.
setContentView(R.Layout.main); View layout for activity define in main.xml at res > layout folder main.xml looks like   

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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>    


Where in linear layout one Text Box show value of hell string from string.xml (res > values > string.xml )


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, TestFrist!</string>
    <string name="app_name">Frist Project</string>
</resources>

Add one more folder drawable  in res folder of Package explorer  by right clicking,Add one image or paste one image in this folder (image name must be small letter ) like loksa2.jpg (prefer .png format)  and in main.xml replace <TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
with
<ImageView android:layout_width="fill_parent" android:id="@+id/imageView1"
        android:layout_height="fill_parent" android:src="@drawable/loksa2"></ImageView>



  Now Right click on project at Project Explorer and choose Run As --> Android Application .  You see the output like this ..........



No comments:

Post a Comment