One of the android getting started development guides-Hello, Android example

Source: Internet
Author: User
Tags processing text

 One of the android getting started development guides -- hello, Android example (I)

Hello, Android example

The first impression is very important. As a developer, you know that the first impression of a development framework is to write "Hello, word !", In Android, this is very simple. The implementation steps are as follows:

· Create a project

· Build a user interface

· Run: Hello, Android code

The sections below spell it all out in detail.

The following is a detailed explanation:

· Compressing the UI to the XML Layout

· Debug your project

· Create a project without relying on Eclipse

The exciting time is up. Hurry up!

 

Create a project

Creating a project is simple. An eclipse plug-in can make Android development faster. You need to install eclipse3.3 (europa) or later, and you need to install the android plug-in under eclipse. Once you have installed these programs, you will be back immediately.

First, here's a high-level summary of how to build "Hello, world! ":

First, the following is a high-level summary of how to create "Hello, world !" .

1. Use File> New> new Android project to create a new "android project ".

2. Fill in the project details in the new Android project dialog box.

3. Edit the automatically generated source code template to display the relevant output.

Next, we will describe the entire process step by step.

 

 

1. Create a new Android Project

Select File> New> project from eclipse. if androidadt is successfully installed, the dialog box is named "android", which contains a simple entry: "android project ".

Once you select "android Project", click "Next.

2. Fill in project details

The displayed window allows you to enter detailed information for your project. The following is an example:

 

The following is the meaning of each domain in the screen display window:

Project name
You want to store the computer path name of your project.
 
Package name
Package namespace-similar to the Java programming language-the space you want to save your source code. This also sets the package name of the original object to be generated.

The package name used in your application must be different from the package name of all the installation packages in your system. For this reason, it is very important to name a standard domain style package for your application. In the above example, we use the package domain name "com. Google. Android". For your project team, you can use a different and appropriate domain structure name.
 
Entity name
The object name is the name of the original class generated by the plug-in. It is a subclass of the android entity class. An object is a simple class that can run and work. It can create a user interface or not create a user interface.
 
Application name
The application has a good reading title
 

The "use default location" option box allows you to change the storage location of the generated and saved project files on the disk.

3. Edit the automatically generated source code

After the plug-in runs, you will get a class similar to the following: helloandroid.

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 );

}

}

The following is how to modify it!

Build user interface

Once you have set up the project, the next step is to enter the code on the screen. The following is the project after completion-Next we will analyze it in a row.

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 );

}

}

In Android, the user interface is constructed by class and subclass called view. A view is a simple and printable object, such as a single clip, animation, or (in our example) text tag. The specific sub-class for processing text is textview.

The following shows how to construct a textview class.

Textview TV = new textview (this );

The parameter of the text constructor is an android context instance pointer. This context is a simple system handle that provides processing resources and access to the database and parameter selection. The object class is integrated from the context class. Although our helloandroid class is an object subclass, it is also a context class, so we can pass 'eas' to reference textview .:

Once textview is constructed, we need to tell it what to display:

TV. settext ("Hello, Android ");

There is no accident.

Here, we construct a textview and tell it what to display. The final step is to associate the textview with the screen display, as shown below:

Setcontentview (TV );

The setcontentview () method in the object is associated with the object's user interface and the content is displayed on the system. If an object does not call this method, the system will not have a UI and the system will display a black screen. We want to display some text on the screen, so we pass context to the textview we just created.

This is the "Hello, world" in Android. Next, of course, let's take a look at the running effect!

Note: add a line of code to the generated code as follows:

Import Android. widget. textview;

Otherwise, the following error message appears.

Textview can't be resolved to a type;

Run the code: Hello, Android

 

Eclipse plug-ins make it easier to run applications. Start from this menu entry: Run> RUN configure; you will see the following dialog box.

Next, select "Android Application", click the icon in the upper-left corner (a page is displayed with a plus sign in the upper-left corner), or double-click the "android applicton" portal, you will see a starter named "new_configuration.

 


Change the name to meaningful ones, such as "Hello, Android", and click the Browse button to select your project. (If you open more than one android project in eclipse, make sure that the correct one is selected .) this plugin automatically scans the object subclass in your project and adds each object to the object drop-down list. Because your "Hello, Android" project has only one object, so it is the default one. You only need to simply continue.

Click "application". The following is an example:

 

Great!-You have done everything! Click the run button to run the android simulator. Once the simulator is started, your application is displayed, and it is exciting to see a similar qualified interface:

This is the "Hello, world" example of Android. Is it very simple? The following sections of the Guide will provide more details. When you learn more about Android, you will find many valuable things.

 

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.