I. Preface
This helloworld only has three lines of code, all of which are used to show Android's directory structure and basic development methods to friends who have never done android.
If you have never used intellij idea and do not build the environment, go to: http://blog.csdn.net/juyangjia/article/details/9471561
2. Development steps in intellij idea 12
1. create a project, get your project name, and select the development platform (SDK version). The selection of this version is more important, because if you select Android 4. X development platform, then this program is in Android 2. X or 3. X cannot run.
If no options are available, go:
Http://blog.csdn.net/juyangjia/article/details/9471561
2. After the next step, you will see this page. Select the debugging method. In this example, use the simulator and select the simulator in the red box. If there are no options, go:
Http://blog.csdn.net/juyangjia/article/details/9471561
3. After finishing, the following directory structure is displayed:
(1) This folder contains a series of subfolders, including information inside intellij idea.
(2) It is used to store static files to be packaged into applications for deployment to devices.
(3) generate a directory after compilation
(4) This folder contains the resource files used by the R. java file to link the entire project. It is very important that you do not need to manually modify the file and generate it automatically.
(5) lib package
(6) system resources, interface layout files, images, including all resources needed
(7) interface layout file directory. The layout of all interfaces is xml files, which tastes very similar to html.
(8) It is mainly used to define the strings used by the project. You can also add the color. xml file to add the colors used by our application.
(9) All the code is in this directory.
(10) describes the components exposed in the package (activities, services, and so on), their respective implementation classes, various data that can be processed and startup locations, a bit of web. cofig flavor
(11) referenced jar packages
4. Open the automatically generated
You can see that there are two lines of code by default. The first line does not explain, And the constructor of the parent class is called. The second line is explained in the comments, as shown in the picture.
5. Next, open res/layout/main. xml, drag a TextView control to the interface, and set its id.
Then we can see the Design and Text labels at the bottom of the interface, which are view mode and Text mode. Click Text to see the following xml generated:
<?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="Hello World, MyActivity" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Text" android:id="@+id/textView" android:layout_gravity="left|center_vertical"/></LinearLayout>
6. Write the following code and click the green triangle running program in the menu bar.
Code explanation in the red box:
The first line defines a TextView object. The findViewById method is used to find the control in xml. the id of the control is input when searching. The id cannot be a string directly, and the id defined by R. id. must be used.
The second line sets the value for the TextView control.
The third line is to get its value and put it into a string variable.
The standard java get and set methods are used.
How to add an external jar package? Please go:
View http://blog.csdn.net/juyangjia/article/details/9471561
Click the green triangle in the menu bar and you will see that the status bar at the bottom is being compiled:
7. If you do not select a simulator when creating a project, the following dialog box is displayed:
8. After a long wait, you can see the running (the simulator is very slow, so be patient and wait. Do not think the program is dead ):
Source code download: http://download.csdn.net/detail/juyangjia/5818233
Iii. Brief introduction to the android Project
1. The new project has a default Activity class. What is Activity?
Public class MyActivity extends Activity {}
You can understand it as a display interface.
2. What is the use of the R class?
R. id. textView is to use the R class to retrieve all resources under the res directory. To put it bluntly, the R class is the bridge between the Activity Interface Class and the resource file, and resources are obtained through R.
3. Manually write the interface layout xml file. Why cannot I set the id?
The standard id settings are as follows: android: id = "@ + id/textView", for example, @ + id/_ Txt_boardThe red bold part is the Set id. The preceding @ + id/must be fixed.