Android Tutorial: Android Create new project and develop

Source: Internet
Author: User

Android Tutorial: Android to create a new project and development, this article is relatively simple knowledge, more suitable for the students to see, of course, we can also look at my summary, to small make a little comments, say your views!

Creating a new project is simple, as long as you install the Eclipse plugin and your Eclipse software version is at 3.2 or 3.3, you can start developing.

First, take a look at what steps the world program has taken from the advanced level to create Hello:

1. Create a new project through the Project menu, File-, Android project

2. Fill in the parameters of the new project.

3. Edit the automatically generated code template.

That's all, let's complete each step with the detailed instructions below.

1. Create a new Android project

Launch Eclipse, choose the File---New Project menu, and if you have installed your Android Eclipse plugin, you will see the Android Project option in the popup dialog box.

Select "Android Project" and click on the Next button.

2. Fill in the project details parameter project name: The folder that contains the item.

Package name, which follows the Java specification, is important to distinguish between different classes with the package name, in the case of com.google.android, you should have a name that is different from the path you plan to follow.

Activity name: This is the main class name of the project, and this class will be the subclass of the activity class of Android. An activity class is a simple startup process.

and control program classes. It can create an interface as needed, but it is not required.

Application Name: An easy-to-read title on your application.

The Use default location option in the selection bar allows you to select an existing project.

3. Edit the automatically generated code

When the project is created, the helloandroid you just created will contain the following code.

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

}

}

Let's start by modifying it [build interface] When a project is established, the most direct effect is to display some text on the screen, following the completed code, which we will explain on a row-by-line basis.

Java 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 You also need to add import android.widget.TextView; At the beginning of the code. In the Android program, the user interface is organized by a class called views.

A view can be simply understood as an object that can be drawn, such as a Select button, an animation, or a text label (in this program), which is called the TextView of the view subclass that displays the text label.

How to construct a TextView:

Texiview TV = new TextView (this); The TextView is a context instance of the Android program, and the context can control the system invocation, which provides such things as resource resolution, access to the database, and so on. The activity class inherits from the context class, because our helloandroid is a subclass of activity, so it is also a context class, so we can use this in the TextView construct. After we have constructed the TextView, we need to tell it what it shows: Tv.settext (Hello, Android); This step is very simple, when we have completed these steps, we will finally display the TextView on the screen. Setcontentview (TV); The activity's Setcontentview () method indicates which view the system will use as the activity interface, and if an activity class does not execute this method, there will be no interface and display white screen. In this program, we want to display the text, so we pass in the created TextView.

OK, the program code has been written, the following to see the effect of running. Run code: Hello, Android's Eclipse plugin for Android makes it easy to run your program and choose Run-and Open run Dialog. You will see the following dialog box next, highlight the Android Application tab, then press the icon in the upper left corner (just like a piece of paper tape a little star), or simply double-click on the Android Application tab and you will see a new run project named new _configuration. Take a name that can be ideographic, such as Hello, Android, and then select your project via the browser button (if you have many projects in eclipse, make sure you select the project to run), The plugin then automatically searches the activity class in your project and adds all the found to the drop-down list in the Activity tab. We only have hello, Android a project, so it will be selected as the default. Click the Apply button, it's done, you just need to click the Run button, and then the Android emulator will start and your app will be displayed.

Android Tutorial: Android Create new project and develop

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.