1page.title=Notepad Tutorial 2@jd:body 3 4 5<p>This tutorial on writing a notepad application gives you a "hands-on" introduction 6to the Android framework and the tools you use to build applications on it. 7Starting from a preconfigured project file, it guides you through the process of 8developing a simple notepad application and provides concrete examples of how to 9set up the project, develop the application logic and user interface, and then 10compile and run the application. </p> 11 12<p>The tutorial presents the application development as a set of 13exercises (see below), each consisting of several steps. You should follow 14the steps in each exercise to gradually build and refine your 15application. The exercises explain each step in detail and provide all the 16sample code you need to complete the application. </p> 17 18<p>When you are finished with the tutorial, you will have created a functioning 19Android application and will have learned many of the most important 20concepts in Android development. If you want to add more complex features to 21your application, you can examine the code in an alternative implementation 22of a Note Pad application, in the 23<a href="{@docRoot}resources/samples/index.html">Sample Code</a> section. </p> 24 25 26<a name="who"></a> 27<h2>Who Should Use this Tutorial</h2> 28 29<p>This tutorial is designed for experienced developers, especially those with 30knowledge of the Java programming language. If you haven't written Java 31applications before, you can still use the tutorial, but you might need to work 32at a slower pace. </p> 33 34<p>Also note that this tutorial uses 35the Eclipse development environment, with the Android plugin installed. If you 36are not using Eclipse, you can follow the exercises and build the application, 37but you will need to determine how to accomplish the Eclipse-specific 38steps in your environment. </p> 39 40<a name="preparing"></a> 41<h2>Preparing for the Exercises</h2> 42 43<p>The tutorial assumes that you have some familiarity with basic Android 44application concepts and terminology. If you are not, you 45should read <a href="{@docRoot}guide/topics/fundamentals.html">Application 46Fundamentals</a> before continuing. </p> 47 48<p>This tutorial also builds on the introductory information provided in the 49<a href="{@docRoot}resources/tutorials/hello-world.html">Hello World</a> 50tutorial, which explains how to set up your Eclipse environment 51for building Android applications. We recommend you complete the Hello World 52tutorial before starting this one.</p> 53 54<p>To prepare for this lesson:</p> 55 56<ol> 57 <li>Download the <a href="codelab/NotepadCodeLab.zip">project 58 exercises archive (.zip)</a>.</li> 59 <li>Unpack the archive file to a suitable location on your machine.</li> 60 <li>Open the <code>NotepadCodeLab</code> folder.</li> 61</ol> 62 63<p>Inside the <code>NotepadCodeLab</code> folder, you should see six project 64files: <code>Notepadv1</code>, 65 <code>Notepadv2</code>, <code>Notepadv3</code>, 66 <code>Notepadv1Solution</code>, <code>Notepadv2Solution</code> 67 and <code>Notepadv3Solution</code>. The <code>Notepadv#</code> projects are 68the starting points for each of the exercises, while the 69<code>Notepadv#Solution</code> projects are the exercise 70 solutions. If you are having trouble with a particular exercise, you 71 can compare your current work against the exercise solution.</p> 72 73<a name="exercises"></a> 74<h2> Exercises</h2> 75 76 <p>The table below lists the tutorial exercises and describes the development 77areas that each covers. Each exercise assumes that you have completed any 78previous exercises.</p> 79 80 <table border="0" style="padding:4px;spacing:2px;" summary="This 81table lists the 82tutorial examples and describes what each covers. "> 83 <tr> 84 <th width="120"><a href="{@docRoot}resources/tutorials/notepad/notepad-ex1.html">Exercise 851</a></th> 86 <td>Start here. Construct a simple notes list that lets the user add new notes but not 87edit them. Demonstrates the basics of <code>ListActivity</code> and creating 88and handling 89 menu options. Uses a SQLite database to store the notes.</td> 90 </tr> 91 <tr> 92 <th><a href="{@docRoot}resources/tutorials/notepad/notepad-ex2.html">Exercise 2</a></th> 93 <td>Add a second Activity to the 94application. Demonstrates constructing a 95new Activity, adding it to the Android manifest, passing data between the 96activities, and using more advanced screen layout. Also shows how to 97invoke another Activity to return a result, using 98<code>startActivityForResult()</code>.</td> 99 </tr> 100 <tr> 101 <th><a href="{@docRoot}resources/tutorials/notepad/notepad-ex3.html">Exercise 3</a></th> 102 <td>Add handling of life-cycle events to 103the application, to let it 104maintain application state across the life cycle. </td> 105 </tr> 106 <tr> 107 <th><a href="{@docRoot}resources/tutorials/notepad/notepad-extra-credit.html">Extra 108Credit</a></th> 109 <td>Demonstrates how to use the Eclipse 110debugger and how you can use it to 111view life-cycle events as they are generated. This section is optional but 112highly recommended.</td> 113 </tr> 114</table> 115 116 117<a name="other"></a> 118<h2>Other Resources and Further Learning</h2> 119<ul> 120<li>For a lighter but broader introduction to concepts not covered in the 121tutorial, 122take a look at <a href="{@docRoot}resources/faq/commontasks.html">Common Android Tasks</a>.</li> 123<li>The Android SDK includes a variety of fully functioning sample applications 124that make excellent opportunities for further learning. You can find the sample 125applications in the <code>samples/</code> directory of your downloaded SDK, or browser them 126here, in the <a href="{@docRoot}resources/samples/index.html">Sample Code</a> section.</li> 127<li>This tutorial draws from the full Notepad application included in the 128<code>samples/</code> directory of the SDK, though it does not match it exactly. 129When you are done with the tutorial, 130it is highly recommended that you take a closer look at this version of the Notepad 131application, 132as it demonstrates a variety of interesting additions for your application, 133such as:</li> 134 <ul> 135 <li>Setting up a custom striped list for the list of notes.</li> 136 <li>Creating a custom text edit view that overrides the <code>draw()</code> 137 method to make it look like a lined notepad.</li> 138 <li>Implementing a full <code>ContentProvider</code> for notes.</li> 139 <li>Reverting and discarding edits instead of just automatically saving 140 them.</li> 141 </ul> 142</ul> 143