Getting started with Android Program Development

Source: Internet
Author: User

Creating a new project is simple. As long as you have installed the Eclipse plug-in and your Eclipse software version is 3.2 or 3.3, you can start development.

  First, let's take a look at the advanced steps for creating the "Hello, World" program:

1. Create a New Project "Android Project" through the File-> New-> Project menu"

2. Fill in parameters for the new project.

3. Edit the automatically generated code template.

That's all. We will complete each step through the detailed descriptions below.

  1. Create a new Android Project

Start Eclipse and select File> New> Project. If you have installed the Android Eclipse plug-in, you will see the "Android Project" option in the pop-up dialog box.

Select "Android Project" and click "Next.

  2. Fill in detailed project parameters

In the following dialog box, you must enter parameters related to the project:

  This table details the meaning of each parameter:

Project Name: Name of the folder containing the Project.

Package Name: the Package Name follows the JAVA specification. It is important to use the Package Name to distinguish different classes. In this example, "com. google. android ", you should give a name different from this path according to your plan.

Activity Name: this is the main class Name of the project. This class will be a subclass of the Android Activity class. An Activity class is a simple class for starting and controlling programs. It can create an interface as needed, but not required.

Application Name: a readable title on your Application.

In the "Use default location" option in the "select bar", you can select an existing project.

  3. Edit the automatically generated code.

After the project is created, the created HelloAndroid contains the following code.

Public class HelloAndroid extends Activity

{

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

@ Override

Public void onCreate (Bundle icicle)

{

Super. onCreate (icicle );

SetContentView (R. layout. main );

}

}

Next let's modify it.

  [Build interface]

After a project is created, the most direct effect is to display some text on the screen. The following is the completed code, which will be explained in line by line later.

Code

Public class HelloAndroid extends Activity {

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

@ Override

Public void onCreate (Bundle icicle ){

Super. onCreate (icicle );

TextView TV = new TextView (this );

TV. setText ("Hello, Android ");

SetContentView (TV );

}

}

Note that you also need to add import android. widget. TextView; at the beginning of the Code.

In Android, user interfaces are organized by the Views class. A View can be simply understood as an object that can be drawn, such as a selection button, an animation, or a text tag (in this program). The View subclass that displays the text tag is called TextView.

How to construct a TextView:

TexiView TV = new TextView (this );

The TextView constructor is the Context instance of the Android program. Context can control system calls. It provides resource parsing, database access, and so on. The Activity class inherits from the Context class. Because HelloAndroid is a subclass of Activity, it is also a Context class, so we can use "this" in TextView construction.

  After constructing the TextView, we need to tell it what to display:

TV. setText ("Hello, Android ");

This step is simple. After completing these steps, we will display TextView on the screen.

SetContentView (TV );

The setContentView () method of Activity indicates which View is used by the system as the Activity interface. If an Activity class does not execute this method, there will be no interface and a white screen will be displayed. In this program, we want to display the text, so we pass in the created TextView.

Well, the program code has been written. Let's take a look at the running effect.

Run the code: Hello, Android

You can use the Eclipse plug-in of Android to easily Run your program. Choose Run> Open Run Dialog. You will see the following dialog box

Next, highlight the "Android Application" tag, and then press the icon in the upper left corner (like a piece of paper with a small star), or double-click the "Android Application" tag, you will see a new running project named "New_configuration ".

Take a name that can be ideographic, such as "Hello, Android", and then select your project through the Browser button (if you have many projects in Eclipse, make sure you select the project you want to run), then the plug-in will automatically search for the Activity class in your project and add all the found items to the drop-down list of the "Activity" tag. We only have "Hello, Android" project, so it will be used as the default option.

Click "Apply,

Now, you have finished. You only need to click the "Run" button. Then the Android simulator will start and your application will be displayed.

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.