Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

This blog is a step-by-step guide in building your first android application.

0.1.

Install JDK

 Install JDK via the following link :

 

http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u26-download-400750.html     

Extract the contents of the ZIP file

 

0.1.

Install Eclipse

Install Eclipse via the following link :

 

http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/indigor

              >  Download the ZIP file to your local folder

              >  Extract the contents of the ZIP file

              >  Double-click on eclipse.exe to start the eclipse

              >  Enter the folder for the Workspace, and click OK

</p><ul><li>Install the Android SDK</li></ul><p>Install the SDK via the following link :</p><p> [http://developer.android.com/sdk/index.html  | http://developer.android.com/sdk/index.html]</p><p> </p><ul><li>Install Eclipse ADT(Android Development Tools) Plug-In*

                     >  Start Eclipse

                     > Click on Help -> Install New Software

                     

                    > Click "Add" in the right corner

 !https://weblogs.sdn.sap.com/weblogs/images/33546/Add.png|height=129|alt=image|width=445|src=https://...!

                    > In the "Add Repository" dialog, enter the path as shown below,    and click OK

 !https://weblogs.sdn.sap.com/weblogs/images/33546/AddRepository.png|height=81|alt=image|width=362|src...!

                    > Select the "Check Box" against "Developer Tools" and click "Next"

                    > In the next window, you'll see a list of the tools to be downloaded.

                    >

Click Next.

                    >

Click Finish.

                    > When the installation completes, restart Eclipse.

 

Configure ADT Plug-In                    > Start Eclipse

                    > Select Window -> Preferences

                    > Select "Android" from the left panel, enter the downloaded SDK location and click "Apply" and then "OK"

 !https://weblogs.sdn.sap.com/weblogs/images/33546/AndroidPreferences.png|height=273|alt=image|width=4...!

 

0.1.

Configure the Android Simulator               > Start Eclipse 

               > Click on Window -> Android SDK and AVD Manager

               > Select "Virtual Devices" in the left panel and click on "New"

               > In the dialog , enter as shown below

 !https://weblogs.sdn.sap.com/weblogs/images/33546/Device.png|height=407|alt=image|width=303|src=https...!

0.1.

Test your configuration by writing a simple application               > Start Eclipse

               > Click on New -> Project

               > Select "Android Project" and click on "Next"

               > Enter the attributes of the project and click "Finish"

 !https://weblogs.sdn.sap.com/weblogs/images/33546/ProjectAttributes.png|height=500|alt=image|width=37...!

         

         > The project "myFirstApplication" will show the nodes as shown below

 

 !https://weblogs.sdn.sap.com/weblogs/images/33546/myFirstApplication.png|height=185|alt=image|width=2...!

            

            > Double-Click on AndroidManifest.xml

 

 

         > Click on the tab "Instrumentation", and then "Add"

image

 

         > Select "Instrumentation" in the dialog

         > Click on "Browse" against the name

image

 

         > Wait for the system to find a matching runner, and then select the matching item, and click OK

image

         > Select the package, and then click on "Save"

 !https://weblogs.sdn.sap.com/weblogs/images/33546/Instrumentation.png|height=198|alt=image|width=438|...!

 

 *        Now lets write a simple application to display a text , on click of a button</p><p>         > Lets add a button and a Textbox in the layout</p><p>         > Click on "Main.XML", and modify the XML as shown below</p><p>!https://weblogs.sdn.sap.com/weblogs/images/33546/Main.PNG|height=227|alt=image|width=192|src=https:/...!</p><p>*XML Layout **********************************************</p><p><?xml version="1.0" encoding="utf-8"?><br /><LinearLayout xmlns:android="[http://schemas.android.com/apk/res/android | http://schemas.android.com/apk/res/android]"<br />    android:orientation="vertical"<br />    android:layout_width="fill_parent"<br />    android:layout_height="fill_parent"<br />    ><br /><TextView  <br />    android:layout_width="fill_parent" <br />    android:layout_height="wrap_content" <br />    android:text="Hi Android"<br />    />    <br /><TextView  <br />    android:id="@id/result" <br />    android:layout_width="fill_parent" <br />    android:layout_height="wrap_content" <br />    android:text=""</p><p>    /><br /><Button <br />  android:text="Display Text" <br />  android:id="@id/button_text" <br />  android:layout_width="wrap_content" <br />  android:layout_height="wrap_content"><br />  </Button>    <br /></LinearLayout></p><p>************************************************************

image

 

    **  Note that the name of the text view is "result" and name of the button is "button_text"

Lets go back and write some code to finish our application

         > Click on "myFirstApplicationActivity" and write the following code :

 

 

    • Start of  Code **********************************************</p><p>package myFirstApplication.com;<br />import android.app.Activity;<br />import android.os.Bundle;<br />import android.view.;

import android.widget.Button;

import android.widget.TextView;

public class MyFirstApplicationActivity extends Activity {

 private TextView result; 

    /** Called when the activity is first created. /<br />    @Override<br />    public void onCreate(Bundle savedInstanceState) {<br />        super.onCreate(savedInstanceState);<br />        setContentView(R.layout.main);<br />        result = (TextView)findViewById(R.id.result);<br />        Button button_text = (Button)findViewById(R.id.button_text);<br />        button_text.setOnClickListener(new Button.OnClickListener() <br />         { <br />         public void onClick (View v)<br />          { <br />          display_text(); <br />             }<br />         }<br />        );        <br />    }<br />    public void display_text()<br /> {<br />       result.setText("[www.sap.com | http://www.sap.com]");</p><p> }      <br />}</p><p>**************************************************************

image

****************************************************************

 

         > Run the application by clicking on "Run" in the menu bar and then select "Android Application" in the dialog

 !https://weblogs.sdn.sap.com/weblogs/images/33546/RunasAndroid.png|height=330|alt=image|width=206|src...!

   >  Wait for a few seconds until , we see the following screen :

 !https://weblogs.sdn.sap.com/weblogs/images/33546/Android.png|height=446|alt=image|width=459|src=http...

 

Wait for about 40-60 secs to see your application, then click on the home in the right hand side, or unlock the application

Here it is !!!  "myFirstApplication".

!https://weblogs.sdn.sap.com/weblogs/images/33546/andapps.PNG|height=500|alt=image|width=479|src=http...!

 

!https://weblogs.sdn.sap.com/weblogs/images/33546/Firstapps.PNG|height=177|alt=image|width=379|src=ht...!

 

 

Click on "myFirstApplication".

!https://weblogs.sdn.sap.com/weblogs/images/33546/Executefirstapps.PNG|height=294|alt=image|width=457...!

 

Click on the button "Display Text" to see the text www.sap.com (http://www.sap.com).

 

!https://weblogs.sdn.sap.com/weblogs/images/33546/result.PNG|height=259|alt=image|width=334|src=https...!

4 Comments