记事本教程

Notepad Tutorial

记事本教程

This tutorial on writing a notepad application 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 application development as a set of exercises (see below), each consisting of several steps. You should follow the steps in each exercise to gradually build 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 will have learned many of the most important concepts in Android development. If you want to add more complex features to your application, you can examine the code in an alternative implementation of a Note Pad application, in the Sample Code section.

当你完成了本教程,您将会创建了一个能够正常运行的Android应用程序,并且学会了很多Android开发中至关重要的部分。如果你希望在你的程序中添加更多复杂的功能,你可以参考位于 Sample Code  部分的Note Pad应用程序的代码以选择实现它们。

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 note that this tutorial uses 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.

同时需要注意本教程使用安装了Android补丁的Eclipse开发环境。如果你不是使用Eclipse,你也能跟随练习并完成应用程序,但你需要确定如何在你的开发环境中实现Eclipse的具体步骤。

Preparing for the Exercises

练习前准备

The tutorial assumes that you have some familiarity with basic Android application concepts and terminology. If you are not, you should read Application Fundamentals before continuing.

本教程假定你已经熟悉一些基本的Android应用程序的概念和术语。 如果不是,你应该先阅读 Application Fundamentals 部分之后再继续。

This tutorial also builds on the introductory information provided in the Hello World tutorial, which explains how to set up your Eclipse environment for building Android applications. We recommend you complete the Hello World tutorial before starting this one.

本教程也是构建在 Hello World 教程介绍的信息基础之上, 该教程解释了如何在你的Eclipse环境中构建Android应用程序。 在开始本教程之前,我们假定你已经完成了Hello World教程。

To prepare for this lesson:

本课程准备内容:

  1. Download the project exercises archive (.zip).
  2. Unpack the archive file to a suitable location on your machine.
  3. Open the NotepadCodeLab folder.

  1. 下载 project exercises archive (.zip).
  2. 解压缩文档在你计算机合适的地址
  3. 打开 NotepadCodeLab 文件夹。

Inside the NotepadCodeLab folder, you should see six project files: Notepadv1Notepadv2Notepadv3,Notepadv1SolutionNotepadv2Solution 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.

在 NotepadCodeLab文件夹里,你将会看见六个项目文件: 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 any previous exercises.

下面的表格包括本教程的练习条目并描述了各部分的拓展领域。每个练习都假定你完成了上一个练习。

Exercise 1Start here. Construct a simple notes list that lets the user add new notes but not edit them. Demonstrates the basics of ListActivity and creating and handling menu options. Uses a SQLite database to store the notes.
Exercise 2Add 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 to return a result, using startActivityForResult().
Exercise 3Add handling of life-cycle events to the application, to let it maintain application state across the life cycle.
Extra CreditDemonstrates how to use the Eclipse debugger and how you can use it to view life-cycle events as they are generated. This section is optional but highly recommended.
Exercise 1
开始。构造一个简单的笔记清单,让用户添加新记录,但是不能编辑。演示 ListActivity 的基本知识,并创建和控制菜单选项。使用SQLite 数据库存储这些记录。
Exercise 2
在应用中添加第二个 Activity 。 演示如何构建一个新的 Activity,并将它添加到 Android manifest 清单文件里,在活动之间传递数据,并使用更多的高级屏幕布局。还展示了如何使用 startActivityForResult()方法调用另一项活动并返回结果。
Exercise 3
在应用中添加时间生命周期事件的控制,使其在整个生命周期中持有应用程序的状态。
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 of your downloaded SDK, or browser them here, in the Sample Code section.
  • This tutorial draws from the full Notepad application included in the samples/ directory of the SDK, though it does not match it exactly. When you are done with the tutorial, it is highly recommended that you take a closer look at this version of the 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 包括一系列完整运行的应用程序实例,是进一步学习的完美阶梯。你可以在你所下载的SDK的sample/ 文件夹下找到这些应用示例,或者在这里的 Sample Code 部分。
  • 本教程是参照 SDK 的 samples/ 文件夹中Notepad完整版本设计,虽然它们并不完全匹配。当你完成本教程,强烈建议你仔细研究该版本的Notepad应用程序,它能够为你的应用程序展示了一系列有趣的补充,比如:
    • 为记录表单设置一个普通条纹?
    • 创建一个普通的文本编辑效果来覆盖 draw() 方法,以使得看起来像一个有横条的笔记本。
    • 为记录实现一个完整的 ContentProvider 。
    • 使用可还原和放弃编辑,而不是只能自动保存。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值