一、新建HelloWorld项目: 1、打开Eclipse,点击“File”-New-Project-Android Application Project: 在弹出的“New Android Application”窗体中输入相应的应用名称、项目名称、包名称,并选择相应的SDK版本和应用主题: 选择项目保存位置,一路“next”完成
一、新建HelloWorld项目:1、打开Eclipse,点击“File”->"New"->"Project"-Android Application Project"":
在弹出的“New Android Application”窗体中输入相应的应用名称、项目名称、包名称,并选择相应的SDK版本和应用主题:
选择项目保存位置,一路“next”完成项目创建:
创建后的项目:
在创建后的项目名称上右键单击选择“Run As”->“Android Application”运行刚创建的项目:
运行结果:
二、应用程序目录结构简析:
1、应用程序目录结构:
2、各部分说明:
Activity文件:双击目录中的“MainActivity.java”,可以看到MainActivity的代码:

1 package android.basic.helloandroid; 2 3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.view.Menu; 6 7 public class MainActivity extends Activity { 8 9 @Override 10 protected void onCreate(Bundle savedInstanceState) { 11 super.onCreate(savedInstanceState); 12 setContentView(R.layout.activity_main); 13 } 14 15 @Override 16 public boolean onCreateOptionsMenu(Menu menu) { 17 // Inflate the menu; this adds items to the action bar if it is present. 18 getMenuInflater().inflate(R.menu.activity_main, menu); 19 return true; 20 } 21 22 }

从代码中可以看到MainActivity继承于Activity类,Activity是Android中的视图部分,负责处理界面显示。在MainActivity里面重写了父类的onCreate方法和onCreateOptionsMenu方法,在重写的onCreate方法里方法setContentView(R.layout.activity_main)给MainActivity设置了要显示的视图R.layout.activity_main,视图由R类寻找并加载(感觉很像mvc,Activity相当于Controller而要显示的layout就相当于具体的页面)。
R文件:在MainActivity的setContentView(R.layout.activity_main)方法中我们用R.layout.activity_main指定了要显示的视图,在应用程序目录结构的截图中可以看到R文件位于gen目录下面,双击显示代码:

1 /* AUTO-GENERATED FILE. DO NOT MODIFY. 2 * 3 * This class was automatically generated by the 4 * aapt tool from the resource data it found. It 5 * should not be modified by hand. 6 */ 7 8 package android.basic.helloandroid; 9 10 public final class R { 11 public static final class attr { 12 } 13 public static final class drawable { 14 public static final int ic_launcher=0x7f020000; 15 } 16 public static final class id { 17 public static final int menu_settings=0x7f070000; 18 } 19 public static final class layout { 20 public static final int activity_main=0x7f030000; 21 } 22 public static final class menu { 23 public static final int activity_main=0x7f060000; 24 } 25 public static final class string { 26 public static final int app_name=0x7f040000; 27 public static final int hello_world=0x7f040001; 28 public static final int menu_settings=0x7f040002; 29 } 30 public static final class style { 31 /** 32 Base application theme, dependent on API level. This theme is replaced 33 by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 34 35 36 Theme customizations available in newer API levels can go in 37 res/values-vXX/styles.xml, while customizations related to 38 backward-compatibility can go here. 39 40 41 Base application theme for API 11+. This theme completely replaces 42 AppBaseTheme from res/values/styles.xml on API 11+ devices. 43 44 API 11 theme customizations can go here. 45 46 Base application theme for API 14+. This theme completely replaces 47 AppBaseTheme from BOTH res/values/styles.xml and 48 res/values-v11/styles.xml on API 14+ devices. 49 50 API 14 theme customizations can go here. 51 */ 52 public static final int AppBaseTheme=0x7f050000; 53 /** Application theme. 54 All customizations that are NOT specific to a particular API-level can go here. 55 */ 56 public static final int AppTheme=0x7f050001; 57 } 58 }

从代码中可以看到R文件里面有很多类,每个类里面又有很多变量,这些类和变量在我们添加、删除控件或资源文件(图片、声音等)由开发工具自动帮我们维护的,由它来调用应用程序的各种资源,在代码第一句的注释中也说明了“AUTO-GENERATED FILE. DO NOT MODIFY”。
layout文件:res/layout/activity_main.xml – 布局文件,双击activity_main.xml会进入可视化编辑界面,在这里你可以根据需要选择相应的控件:
也可以点击红框部分进入文本编辑界面直接写对应控件的代码(从截图代码文件可以看到该layout由一个相对布局和一个文本框组成):
AndroidManifest文件:在应用程序目录截图中倒数第四个可以看到一个AndroidManifest.xml文件,它是应用程序的配置文件包含在每个安卓应用程序中,它向系统描述了本程序所包括的组件、所实现的功能、所能处理的数据、要请求的资源等,可以近似看做网站中的Web.conig文件,同样它也可以由可视化编辑器或文本编辑器编辑:
Android.jar文件:Android.jar内部常用包作用概述,如下图所示:
可以看到Android.jar里面包含了很多包,常见包的作用如下:
android.app-----------提供高层的程序模型、提供基本的运行环境
android.content-------包含各种的对设备上的数据进行访问和发布的类
android.database------通过内容提供者浏览和操作数据库
android.graphics-------底层的图形库,包含画布,颜色过滤,点,矩形,可以将他们直接绘制到屏幕上.
android.location-------定位和相关服务的类
android.media---------提供一些类管理多种音频、视频的媒体接口
android.net------------提供帮助网络访问的类,超过通常的java.net.* 接口
android.os-------------提供了系统服务、消息传输、IPC 机制
android.opengl--------提供OpenGL 的工具
android.provider-------提供类访问Android 的内容提供者
android.telephony-----提供与拨打电话相关的API 交互
android.view-----------提供基础的用户界面接口框架
android.util------------涉及工具性的方法,例如时间日期的操作
android.webkit---------默认浏览器操作接口
android.widget---------包含各种UI 元素(大部分是可见的)在应用程序的屏幕中使用

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool