The path of Android development Learning--a preliminary study of programming environment

Source: Internet
Author: User

The first HelloWorld program. Analysis of the documents.

1.androidmanifest.xml is an engineering description file for Android applications that contains macro content

。 The application (for the Application) tab contains an activity (representing the activities), basically each page is an activity, an application may contain multiple activities, it should be modified here, that is, to include multiple pages, such as sliding to another page. There are some basic definitions in this application, Allowbackup,icon,label (which is the application name), them should be optional here, and them optional in the design interface.

The package is defined as: package= "Com.example.dt.myapplication" indicates that Java code will be looked up from the/com/example/dt/myapplication in the SRC directory (Linux or MAC Only? The activity name is specified as. Mainactivity, which indicates that the active code is Mainactivity.java in the above source code directory. Then the program is started in Intent-filter, the category of launcher indicates that the activity will appear on the desktop of Andorid (by default). The label displays the text below the desktop.

Specify label and icon mode for the activity as android:label= "@string/label_name" android:name= "Drawable/icon_name" two lines

2. Mainactivity.java, located in the Java directory, this is the main coding place

Mainactivity is our activity name, and the class name in Java must be a file name that inherits Actionbaractivity (Eclipse integration activity).

Class, the Oncrete method is first overloaded, which is called when the activity is first executed, first super calls the constructor of the parent class, and then calls, Setcontentview (R.layout.activity_main) Represents a call to a layout file Activity_main.xml

The following two overloads the menu method, the first one is to initialize the menu file, Getmenuinflater (). Inflate (R.menu.menu_main, menu); This function indicates that when the menu is initialized, the menu_ of the call Main.xml as its menu file.

@Override
public boolean onoptionsitemselected (MenuItem item) {
Handle Action Bar Item clicks here. The Action Bar would
Automatically handle clicks on the Home/up button, so long
As you specify a the parent activity in Androidmanifest.xml.
int id = item.getitemid ();

Noinspection simplifiableifstatement
if (id = = r.id.action_settings) {
return true;
}

return super.onoptionsitemselected (item);
}

The function is the event that is triggered when the menu is selected, which item is filtered with the ID, and the following can write a SWITHCH statement to perform the corresponding operation.

3. The layout file activity_main.xml the layout file for the program and the layout file is called in the. java file.

There are many UI controls that can be defined in the layout, either directly in XML or by dragging the controls directly. We take RadioButton as an example:

It should be noted here that android:text= "New RadioButton" is not a good way to define a variable in string and then use the @string/radiobutton,android:id= "@+id/ RadioButton "

4.string.xml is a given resource file, which defines some variables.

<string name= "App_name" >my application</string>

<string name= "Hello_world" >hello world!</string>
<string name= "Action_settings" >Settings</string>

Here is the definition of a string variable app_name the value of the variable is similar to the one behind My application two.

In this understanding, after the basic file structure, next, we started to do a basic Android applet with the event.

The path of Android development Learning--a preliminary study of programming environment

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.