Intro/tutorial

From Android中文网

Android中文网(androidcn.net) 版权申明 : creativecommons licenses
Jump to: navigation, search

目录

[编辑] 入门指引:记事本应用

The tutorial in this section gives you a "hands-on" introduction to the Android framework and the tools you use to build applications on it. Starting from a preconfigured project file, it guides you through the process of developing a simple notepad application and provides concrete examples of how to set up the project, develop the application logic and user interface, and then compile and run the application.

在这部分的入门指引中,将有一个实际的例子作为介绍,描述Android框架和构建程序需要用到的工具。从预先配置好的项目文件开始,它将带领你完成开发一个简单记事本程序的全过程,并且提供精简的例子来说明怎样设置项目,应用逻辑和用户界面的开发,之后编译并运行程序。

The tutorial presents the notepad application development as a set of exercises (see below), each consisting of several steps. You can follow along with the steps in each exercise and gradually build up and refine your application. The exercises explain each step in detail and provide all the sample code you need to complete the application.

这个入门指引将记事本应用的开发作为一组练习(见下面),每一个练习都包含了数个步骤。你可以在每个练习中逐步进行,慢慢构建、修改你的程序。每个练习都详细说明了每个步骤并提供了示例代码以帮助你完成记事本应用。

When you are finished with the tutorial, you will have created a functioning Android application and learned in depth about many of the most important concepts in Android development. If you want to add more complex features to your application, you can look at and use the code in the notepad application that is supplied in the sample code area of the Android SDK.

当你完成了该入门,你就已经创建了一个功能性的Android 应用程序,并且已经学习了许多关于Android开发的重要概念。如果你想在你的应用程序中加入更多复杂的特性,你可以查阅、使用Android SDK 在实例代码区域中提供的记事本应用程序。

[编辑] Who Should Use this Tutorial

哪些人应当用这个入门指引

This tutorial is designed for experienced developers, especially those with knowledge of the Java programming language. If you haven't written Java applications before, you can still use the tutorial, but you might need to work at a slower pace.

这个指引是为有经验开发者设计的,尤其是那些已经具备Java语言知识的人。如果你还没有写过Java的应用程序,你仍可以用到这篇文档,但是可能进度会慢些。

Also, the tutorial builds on the information provided in the Installing the SDK and Hello Android documents, which explain in detail how to set up your development environment for building Android applications. Before you start the tutorial, make sure that you have already downloaded the SDK and installed it according to the instructions.

同时,这个指引所述内容是建立在Installing the SDK 和Hello Android 两篇文章提供的基础上,它们详细的介绍了如何搭建Android应用程序的开发环境。在你开始之前,确保你已经下载好SDK并且根据说明安装妥当。

Finally, this tutorial describes how to develop the notepad application in the Eclipse development environment, with the Android plugin installed. If you are not using Eclipse, you can follow the exercises and build the application, but you will need to determine how to accomplish the Eclipse-specific steps in your environment. If you want to add more complex features to your application, you can look at and use the code in the notepad application that is supplied in the sample code area of the Android SDK.

最后,这个指引描述了如何在Eclipse开发环境下(已安装Android plugin 插件)开发notepad应用程序,如果你没有Eclipse,你可以进行练习,构建应用程序,但是你将需要决定如何在你的开发环境中完成Eclipse-specific步骤。如果你想增加复杂的特性在你的应用程序中,你可以查阅、使用Android SDK 在实例代码区域中提供的记事本应用程序。


The tutorial assumes that you have some familiarity with the basic Android application concepts and terminology. If you aren't yet familiar with those, you should read Overview of an Android Application and Application Lifecycle before continuing.

这篇入门指引假设你已经熟悉了Android应用程序的基本概念和相关术语。如果还没有,你应该先阅读Android Application 概览和应用程序生命周期(Application Lifecycle)。

[编辑] Preparing for the Exercises

做好准备

Before you begin, it's important that you install the SDK and set up your Eclipse development. Once your environment is set up, locate and unpack the exercises archive, which is included in the SDK package. The archive includes a series of Eclipse project files that are used in the exercises. You can use these project files instead of creating and configuring your own project files.

在你开始之前,确认你已经安装好SDK并且已经设置好你的Eclipse 环境。之后,解压练习档案到指定的文件夹。档案中包含了一些会用到的Eclipse 工程文件。你可以用这些文件来代替创建和配置自己的工程文件。

To get the tutorial project files:

获得工程文件

Download the project exercises archive (.zip) Unpack the archive file to a suitable location on your machine Open the NotepadCodeLab folder Inside the NotepadCodeLab folder, you should see six project files: Notepadv1, Notepadv2, Notepadv3, Notepadv1Solution, Notepadv2Solution and Notepadv3Solution. The Notepadv* projects are the starting points for each of the exercises, while the Notepadv*Solution projects are the exercise solutions. If you are having trouble with a particular exercise, you can compare your current work against the exercise solution to try and track down the problem.

下载练习用工程档案(.zip)解压缩档案到你的机器上,打开NotepadCodeLab 文件夹。在文件夹里,你应该能看到6个项目文件:Notepadv1, Notepadv2, Notepadv3, Notepadv1Solution, Notepadv2Solution和Notepadv3Solution。每一个练习以Notepadv打头的项目开始,而Notepadv×solution是解决方案。如果你在做某个练习遇到了困难,你可以和解决方案进行对照。

[编辑] Exercises

练习

The table below lists the tutorial exercises and describes the development areas that each covers. Each exercise assumes that you have completed the previous example (if any).

下面的表格列出了练习指引并描述了每一个涉及的开发方面。每个练习都假设你已经完成了前面的练习(如果有的话)。

  1. Exercise 1 Construct a simple notes list that lets the user add new notes but not edit them. Demonstrates the basics of ListActivities and creating and handling menu options. Uses a SQLite database to store the notes.
  2. Exercise 2 Add a second activity to the application. Demonstrates constructing a new Activity, adding it to the Android manifest, passing data between the activities, and using more advanced screen layout. Also shows how to invoke another activity asynchronously using startSubActivity().
  3. Exercise 3 Add handling of life-cycle events to the application, to let it maintain application state across the life cycle.
  4. Extra Credit Demonstrates how to use the Eclipse debugger and how you can use it to view lifecycle events as they are generated. This section is optional but highly recommended.
  5. 练习1 创建一个简单的记事本列表,可以让用户添加记事而不能编辑它们。讲清楚ListActivities和创建操作菜单选项的基本点。利用SQLite数据库来储存记事。
  6. 练习2 向程序中添加第二个activity。该练习示范了创建一个新的Activity,并将它添加到Android清单,在activity之间传递数据,应用更进一步的屏幕布局。同时显示怎样利用startSubActivity()异步的调用其他activity。
  7. 练习3 向程序中添加操作生命周期事件的Handle,从而让它在程序的生命周期内维护程序的状态。
  8. Extra Credit 示范了怎样利用Eclipse调试工具,你怎样用它来检视生命周期事件。这部分是可选的,但重点推荐

[编辑] Other Resources and Further Learning

其他的资源和进一步的学习

For a lighter but broader introduction to concepts not covered in the tutorial, take a look at Common Android Tasks. The Android SDK includes a variety of fully functioning sample applications that make excellent opportunities for further learning. You can find the sample applications in the samples/ directory. This tutorial draws from the full Notepad application included in the samples/ directory of the SDK. When you are done with the tutorial, it is highly recommended that you take a closer look at the full Notepad application, as it demonstrates a variety of interesting additions for your application, such as: Setting up a custom striped list for the list of notes. Creating a custom text edit view that overrides the draw() method to make it look like a lined notepad. Implementing a full ContentProvider for notes. Reverting and discarding edits instead of just automatically saving them.

如果想得到在这片入门指引中没有涉及的,更宽泛的概念性介绍,可以看一下Common Android Tasks。 Android SDK包含了多种全功能的示例程序,为进一步的学习提供了很多绝佳的机会。你可以在samples/文件夹中找到那些示例程序。这篇入门指引抽取自完整的记事本程序,那个程序可以在SDK的samples/文件夹中找到。当你完成了这个指引,推荐你看一下完整的记事本程序,因为它对很多有趣的东西(可以用在你的程序中)做出了示范,例如:

  • 为记事本列表设置一个定制的条带列表。
  • 创建一个定制的文本编辑视图,它重载了draw()方法让它看上去像一个行式的记事本。
  • 为记事本实现了一个完整的内容提供体(ContentProvider)
  • 用返回并且丢弃编辑来替代自动保存它们。
Personal tools