Android
Start

Modified

Overview

To start to understand an Android app, we will create the default app in Eclipse and examine the files created.

Starting at IUS

  1. Copy C:\temp\.android   C:\Users\username\.android
     
  2. Start Eclipse by opening
        C:\eclipse-jee-indigo-win32\eclipse and clicking
  3. Select your workspace for saving files.
     
  4. Set the Android SDK location by:

        Window | Preferences | Android | SDK Location: C:\Progra~1\Android\android-sdk
     

  5. File | New | Project | Android

    Name the project Test1
    Check Build Target Android 3.2
    Package name
    with at least one . in the name.
    Click Finish.
     
  6. To open the Project Explorer click the icon in the lower-left of the Eclipse window or Java in the upper-right.


     
  7. Open Test1/src/edu.../Test1Activity.java
     
  8. Click the upper-left bug and debug as Android Application.
     
  9. After a bit of a wait and with luck, you'll see the emulator:


     
  10. Drag the lock and you should see the results of Test1.



    Two Java files define the code behind the app, two XML files define the view.
     

  11. Click on Java in the upper-right corner to open the Package Explorer.

    Window | New Window

    Expand to display as below:


     

TestActivity1.java

R.java

main.xml

string.xml

Test1Activity.java
package edu.ius.rwisman.Test1;

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

public class Test1Activity extends Activity {
    /** Called when the activity is first created. */
    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
main.xml
<?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>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <string name="hello">Hello World, Test1Activity!</string>
   <string name="app_name">Test1</string>
</resources>
R.java
/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package edu.ius.rwisman.Test1;

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

 

Add your name as part of the view.

Use either the graphical or XML file editor.