Java Write generation

Source: Internet
Author: User

Open Eclipse, select File-new–android application Project "Click to view image" Application name is our app and the name we see in the list of mobile apps. Project name is the project title, the name we see in the project list in Eclipse, and the folder name we can see in workspace. Package name is the package name, the Android system is also a very special name, he is not only the name of the package, or the name of the project in the Android system, the project name in the Android system needs to be unique, so we have to define the package name of the project must be careful not to duplicate names Next we give the project a name, here I give it a name, called firstandroid "click to view the image" eclipse will help you to generate a default package name, please remember to modify the package name, general package name with the domain name inversion, if there is no domain name, you can use COM + Initials of your own name + category (Android or Java) + project name to form a unique project package name next, until finish, the first Android project is created. We can see the structure of the project "Click to view the picture" where layout is stored in our layouts, we can see that by default we create a layout file called Activity_main.xml, open the file in Eclipse, We can see that if the interface "click to view image" at the bottom has 2 tabs, the first tab is a graphical interface where we can drag the controls in, and the second tab is a code area where we can edit the properties of the control. Next we drag a button into the interface. "Click to view Picture" and switch to Code view 1 5 6 11 12 About The root node of the XML document above is Relativelayout, which represents a relative layout in which 2 controls are included:  textview represents a text box  button a button control   The various interface layout elements are described in detail in subsequent chapters. The various UIs are also described in detail in subsequent courses, where we only introduce a few common properties.  android:id: This property defines the unique identity of the control, which can be findviewbyid to get the specified interface component in Java code. Android:layout_width: This property specifies the width of the control. We can use a fixed length value, or you can use Match_parent (which means that the width of the control is the same as the width of the parent control), Wrap_content (indicating that the width of the control depends on the contents of the control)  android:layout_ Height: This property defines the height of the control, and the values that can be used refer to the Android:layout_width property.   The SRC directory of Android projects is where Android source is stored. SRC has a mainactivity class file, the code is as follows 1 package com.zy.android.firstandroid; 2 3 Import Android.os.Bundle; 4 Import android.app.Activity; 5 Import Android.view.Menu; 6/** 7 * 8 * @author Zhangyi 9 * @blog HTTP://WWW.CNBLOGS.COM/BLOG-IT/10 * * */public class Mainactivity extends Ac tivity {@Override protected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); 17 Load Layout file Activity_main.xml Setcontentview (r.layout.activity_main); The @Override the public boolean oncreateoptionsmeNu (Menu menu) {Inflate the menu; This adds items to the action bar if it is present. Getmenuinflater (). Inflate (R . Menu.main, menu); return true; 27} 28 29} This Java class only does one thing-----load the layout. So far, this firstandroid application has been developed and completed.   Then you can run the project. Running an Android application through Eclipse's ADT plugin is simple, as long as 2 steps are required: Run the specified AVD device, and if you are ready to use the real machine as a running, debug environment, you need to use a USB cable to connect the phone, and turn on debug mode. Select the Android item you want to run, right-click the Run as–android Application menu in the pop-up menu. "Click to view image" Then we can see our program on the simulator   "Click to view Image"   The first Android project has been successfully run, then we will analyze the Android application structure       & nbsp                            

Java generation

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.