Learning Android development, ---- configuring the environment,

Source: Internet
Author: User

Install android in eclipse

Download development resources

1. download the latest Android SDK

Http: // CODe.google.com/android/download.html

Select the Windows SDK and decompress it to use it. In order to directly use the SDK tool in the console, add the SDK directory to the path environment variable of windows.

2. Download JDK 6. (Some bugs may occur during JDK 5 development)


After the http://java.sun.com/javase/downloads/index.jsp is installed, set the JDK environment variable (java_home, classpath, PATH)

3. Download eclipse 3.2 and 3.3 (Android IDE development)


Http://www.eclipse.org/downloads/download.php? File =/technology/EPP/downloads/release/indigo/R/eclipse-java-indigo-win32.zip

Update eclipse and download ADT (Android development plug-in)

1. Start eclipse and select help> Software Updates> Find and install ....

2. In the displayed dialog box, select search for new features to install and click Next.

3. Click new remote site.

4. Enter the update plug-in URL in the edit box:

Https://dl-ssl.google.com/android/eclipse/. Click OK.

5. view an updated list and click sfinish.

6. In the returned dialog box, select Android plugin> eclipse integration>

Android development tools and click Next.

7. Select accept terms of the license agreement and click Next.

8. Click Finish.

9. Click Install all.

10. Restart eclipse.

11. Restart eclipse and set the android SDK directory in the android attributes (excluding the tools under the SDK, such as D: \ android_xxxxx ):

A. Select WINDOW> preferences... to open the edit Properties window.

B. Select the android property panel

C. Add the androidsdk directory and Click Browse...

D. Click Apply and OK.

12. Set the attributes of Eclipse's javajdk.

A. Select WINDOW> preferences... to open the edit Properties window.

B. Select the Java property panel.

C. Select Java compiler 6.0

D. Click Apply and OK.

Use eclipse to develop Android applications

Use eclipseide to develop an Android Application. First, create an android project, and then set the app startup configuration. Then you can edit the code, start and debug the application.

Create an android Project

The ADT plug-in provides a new project Wizard to help us quickly create an android project and edit the code of an existing Android project.

Follow these steps to create an android project:

1. Select File> New> Project

2. Select Android> Android project, and click Next.

3. Set the purpose of the project

O select create new project in workspace to create a new

Android project: Enter the project name, the Development Kit name of the Code, the Class Name of the application interface, and the name of the application title.

O select Create project from existing source to create a project based on the existing code. This option can be used to create and run the example application provided by Google (which can be found in the android SDK directory)

4. Click Finish.

The ADT plug-in will create these files and directories for your project:

* Src/directory where code files are stored.

* Res/resource file directory.

* Main configuration file of the androidmanifest. XML application project.

Create a STARTUP configuration

Before using the eclipse debugging program, you must create a STARTUP configuration for the project:

1. Select Run> open run dialog... or run> open debug dialog...

2. Select Android Application on the left and click New.

3. Enter a configuration name.

4. In the android option, select the most application startup main interface on the application interface.

5. Click Apply to save the configuration and click Run or debug To Start program debugging.

Debug the application

Once the project STARTUP configuration is set up, you can debug the program by following the steps below: Select Run> RUN or run> debug from the main menu of Eclipse.

If necessary, you can reconfigure the startup parameters (for example, select another program interface as the main startup interface)

Hello, android!

After the environment is configured, you can write the first helloworld for Android. The steps for developing a general Android Application include the following:

* Create a project

* Construct the UI

* Run the program

Create a project

The following figure shows how to create a helloworld project.

1. Create a new Android Project

Select "android project" and click Next button.

2. Enter the project name.

Here's what each field on this screen means:

Project name the name of the directory where the project is stored in the computer

Package name package name-refer to Java-related concepts such as com. China. Hello

Activity name the class name in the UI window, inherited from activity

Application name application title name

3. Easy and automatically generated code:

The generated code is similar:

Package com. China. Hello;

IMPORT Android. App. activity;

IMPORT Android. OS. Bundle;

Public class hellochina extends activity {

/** Called when the activity is first created .*/

@ Override

Public void onCreate (bundle icicle ){

Super. OnCreate (icicle );

Setcontentview (R. layout. Main );



Construct the UI

This is the final helloworldaandroid code, which will be explained one by one.

Package com. China. Hello;

IMPORT Android. App. activity;

IMPORT Android. OS. Bundle;

IMPORT Android. widget. textview;

Public class hellochina extends activity {

/** Called when the activity is first created .*/

@ Override

Public void onCreate (bundle icicle ){

Super. OnCreate (icicle );

// Setcontentview (R. layout. Main );

Textview TV = new textview (this );

TV. settext ("This Is A helloworld test for Android ");

Setcontentview (TV );


} Add imp before the classORT Android. widget. textview; (Concepts in Java are not described much)

In Android, user interface controls are encapsulated into various classes called views. A view is a control object that can be displayed, such as radiobutton, animation, and textlable. One simple control is textview:

Textview TV = new textview (this );

The input parameter of the textview constructor is a context
Objects, such as loading resources, accessing databases, and sharing data. Activity Class from context
Class, so activity itself is a context (the concept of inheritance in Java ).

After the textview object is built, you can set the data to be displayed.

TV. settext ("This Is A helloworld test for Android ");

Connect textview to the screen, as shown in the following code:

Setcontentview (TV );

The setcontentview () method can be used to control which control is associated with the system UI.

The solution is to set as the main display view ). If not set, the screen will be blank.

Running Program: Hello, Android

Click Run to see the following window (for how to configure startup parameters, refer to the previous section)

The simulator starts up and the application starts up.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.