diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-02-10 15:44:00 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-02-10 15:44:00 -0800 |
commit | d24b8183b93e781080b2c16c487e60d51c12da31 (patch) | |
tree | fbb89154858984eb8e41556da7e9433040d55cd4 /docs/html/guide/tutorials | |
parent | f1e484acb594a726fb57ad0ae4cfe902c7f35858 (diff) | |
download | frameworks_base-d24b8183b93e781080b2c16c487e60d51c12da31.zip frameworks_base-d24b8183b93e781080b2c16c487e60d51c12da31.tar.gz frameworks_base-d24b8183b93e781080b2c16c487e60d51c12da31.tar.bz2 |
auto import from //branches/cupcake/...@130745
Diffstat (limited to 'docs/html/guide/tutorials')
-rw-r--r-- | docs/html/guide/tutorials/hello-world.jd | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | docs/html/guide/tutorials/notepad/codelab/NotepadCodeLab.zip | bin | 362176 -> 431473 bytes | |||
-rw-r--r-- | docs/html/guide/tutorials/notepad/notepad-ex1.jd | 3 | ||||
-rw-r--r-- | docs/html/guide/tutorials/notepad/notepad-ex2.jd | 95 | ||||
-rw-r--r-- | docs/html/guide/tutorials/notepad/notepad-ex3.jd | 3 | ||||
-rw-r--r-- | docs/html/guide/tutorials/notepad/notepad-extra-credit.jd | 6 | ||||
-rw-r--r-- | docs/html/guide/tutorials/views/hello-mapview.jd | 2 | ||||
-rw-r--r-- | docs/html/guide/tutorials/views/index.jd | 56 |
8 files changed, 88 insertions, 79 deletions
diff --git a/docs/html/guide/tutorials/hello-world.jd b/docs/html/guide/tutorials/hello-world.jd index c993048..bbc4f77 100644 --- a/docs/html/guide/tutorials/hello-world.jd +++ b/docs/html/guide/tutorials/hello-world.jd @@ -330,7 +330,7 @@ you saw before! After all, the point was to show that the two different layout approaches produce identical results.</p> <p>There's a lot more to creating these XML layouts, but that's as far as we'll go -here. Read the <a href="{@docRoot}guide/topics/views/index.html">Views and Layout</a> documentation for more +here. Read the <a href="{@docRoot}guide/topics/ui/index.html">User Interface</a> documentation for more information on creating layouts.</p> <div class="special"> diff --git a/docs/html/guide/tutorials/notepad/codelab/NotepadCodeLab.zip b/docs/html/guide/tutorials/notepad/codelab/NotepadCodeLab.zip Binary files differindex 86f5e9d..c7dd989 100755..100644 --- a/docs/html/guide/tutorials/notepad/codelab/NotepadCodeLab.zip +++ b/docs/html/guide/tutorials/notepad/codelab/NotepadCodeLab.zip diff --git a/docs/html/guide/tutorials/notepad/notepad-ex1.jd b/docs/html/guide/tutorials/notepad/notepad-ex1.jd index 45ed97e..b7f42bf 100644 --- a/docs/html/guide/tutorials/notepad/notepad-ex1.jd +++ b/docs/html/guide/tutorials/notepad/notepad-ex1.jd @@ -1,4 +1,6 @@ page.title=Notepad Exercise 1 +parent.title=Notepad Tutorial +parent.link=index.html @jd:body @@ -584,5 +586,4 @@ the zip file to compare with your own.</p> <p>Once you are ready, move on to <a href="notepad-ex2.html">Tutorial Exercise 2</a> to add the ability to create, edit and delete notes.</p> -<p><a href="index.html">Back to the Tutorial main page...</a></p> diff --git a/docs/html/guide/tutorials/notepad/notepad-ex2.jd b/docs/html/guide/tutorials/notepad/notepad-ex2.jd index b4608fb..3b8fa0b 100644 --- a/docs/html/guide/tutorials/notepad/notepad-ex2.jd +++ b/docs/html/guide/tutorials/notepad/notepad-ex2.jd @@ -1,9 +1,12 @@ page.title=Notepad Exercise 2 +parent.title=Notepad Tutorial +parent.link=index.html @jd:body <p><em>In this exercise, you will add a second Activity to your notepad application, to let the user -create, edit, and delete notes. The new Activity assumes responsibility for creating new notes by +create and edit notes. You will also allow the user to delete existing notes through a context menu. +The new Activity assumes responsibility for creating new notes by collecting user input and packing it into a return Bundle provided by the intent. This exercise demonstrates:</em></p> <ul> @@ -11,6 +14,7 @@ demonstrates:</em></p> <li><em>Invoking another Activity asynchronously using <code>startActivityForResult()</code></em></li> <li><em>Passing data between Activity in Bundle objects</em></li> <li><em>How to use a more advanced screen layout</em></li> +<li><em>How to create a context menu</em></li> </ul> <div style="float:right;white-space:nowrap"> @@ -51,7 +55,8 @@ Tools</strong> > <strong>Fix Project Properties</strong>.</p> </li> <li> There are also a couple of new overridden methods - (<code>onListItemClick()</code> and <code>onActivityResult()</code>) + (<code>onCreateContextMenu()</code>, <code>onContextItemSelected()</code>, + <code>onListItemClick()</code> and <code>onActivityResult()</code>) which we will be filling in below. </li> </ul> @@ -59,59 +64,62 @@ Tools</strong> > <strong>Fix Project Properties</strong>.</p> <h2>Step 2</h2> - <p>Add an entry to the menu for deleting a note:</p> +<div class="sidebox"> +<p>Context menus should always be used when performing actions upon specific elements in the UI. +When you register a View to a context menu, the context menu is revealed by performing a "long-click" +on the UI component (press and hold the touchscreen or highlight and hold down the selection key for about two seconds).</p> +</div> + +<p>First, let's create the context menu that will allow users to delete individual notes. +Open the Notepadv2 class.</p> + <ol> + <li>In order for each list item in the ListView to register for the context menu, we call + <code>registerForContextMenu()</code> and pass it our ListView. So, at the very end of + the <code>onCreate()</code> method add this line: + <pre>registerForContextMenu(getListView());</pre> + <p>Because our Activity extends the ListActivity class, <code>getListView()</code> will return us + the local ListView object for the Activity. Now, each list item in this ListView will activate the + context menu. <li> - In the <code>onCreateOptionsMenu()</code> method, add a new line: - <pre>menu.add(0, DELETE_ID, 0, R.string.menu_delete);</pre> - </li> - <li> - The whole method should now look like this:<br> + Now fill in the <code>onCreateContextMenu()</code> method. This callback is similar to the other + menu callback used for the options menu. Here, we add just one line, which will add a menu item + to delete a note. Call <code>menu.add()</code> like so: <pre> -@Override -public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - menu.add(0, INSERT_ID, 0, R.string.menu_insert); +public boolean onCreateContextMenu(Menu menu, View v + ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, v, menuInfo); menu.add(0, DELETE_ID, 0, R.string.menu_delete); - return true; }</pre> + <p>The <code>onCreateContextMenu()</code> callback some passes other information in addition to the Menu object, + such as the View that has been triggered for the menu and + an extra object that may contain additional information about the object selected. However, we don't care about + these here, because we only have one kind of object in the Activity that uses context menus. In the next + step, we'll handle the menu item selection.</p> </li> </ol> <h2>Step 3</h2> - <p>In the <code>onMenuItemSelected()</code> method, add a new case for - <code>DELETE_ID</code>:</p> - <pre> -mDbHelper.deleteNote(getListView().getSelectedItemId()); -fillData(); -return true;</pre> - - <ol> - <li> - Here, we use the <code>deleteNote</code> method to remove the note specified by ID. - In order to get the ID, we call <code>getListView().getSelectedItemId()</code>. - </li> - <li> - Then we fill the data to keep everything up to date. - </li> - </ol> - <p> - The whole method should now look like this:</p> - <pre> -@Override -public boolean onMenuItemSelected(int featureId, MenuItem item) { + <p>Now that the we've registered our ListView for a context menu and defined our context menu item, we need + to handle the callback when it is selected. For this, we need to identify the list ID of the + selected item, then delete it. So fill in the + <code>onContextItemSelected()</code> method like this:</p> +<pre> +public boolean onContextItemSelected(MenuItem item) { switch(item.getItemId()) { - case INSERT_ID: - createNote(); - return true; case DELETE_ID: - mDbHelper.deleteNote(getListView().getSelectedItemId()); + AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); + mDbHelper.deleteNote(info.id); fillData(); return true; } - - return super.onMenuItemSelected(featureId, item); + return super.onContextItemSelected(item); }</pre> +<p>Here, we retrieve the {@link android.widget.AdapterView.AdapterContextMenuInfo AdapterContextMenuInfo} +with {@link android.view.MenuItem#getMenuInfo()}. The <var>id</var> field of this object tells us +the position of the item in the ListView. We then pass this to the <code>deleteNote()</code> +method of our NotesDbAdapter and the note is deleted. That's it for the context menu — notes +can now be deleted.</p> <h2 style="clear:right;">Step 4</h2> <div class="sidebox" style="border:2px solid #FFFFDD;float:right; @@ -294,8 +302,8 @@ case ACTIVITY_EDIT: but that doesn't mean it is even close to the kind of sophistication you will be likely to want in real Android applications.</p> <p style="padding-left:.5em;font-size:12px;margin:0; padding:.0em .5em .5em 1em;">Creating a - good UI is part art and part science, and the rest is work. Mastering <a - href="{@docRoot}guide/topics/views/declaring-layout.html">Android layout</a> is an essential part of creating + good UI is part art and part science, and the rest is work. Mastery of <a + href="{@docRoot}guide/topics/ui/declaring-layout.html">Declaring Layout</a> is an essential part of creating a good looking Android application.</p> <p style="padding-left:.5em;font-size:12px;margin:0; padding:.0em .5em .5em 1em;">Take a look at the @@ -570,7 +578,7 @@ protected void onCreate(Bundle savedInstanceState) { receive, and more. </p> <p style="padding-left:.5em;font-size:12px;margin:0; padding:.0em .5em .5em 1em;">For more information, see the reference document - <a href="{@docRoot}guide/topics/manifest/manifest.html">AndroidManifest.xml</a></p> + <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">The AndroidManifest.xml File</a></p> </div> <p>Finally, the new Activity has to be defined in the manifest file:</p> @@ -636,5 +644,4 @@ Once you are ready, move on to <a href="notepad-ex3.html">Tutorial Exercise 3</a> where you will fix the problems with the back button and lost edits by introducing a proper life cycle into the NoteEdit Activity.</p> -<p><a href="index.html">Back to the Tutorial main page...</a>.</p> diff --git a/docs/html/guide/tutorials/notepad/notepad-ex3.jd b/docs/html/guide/tutorials/notepad/notepad-ex3.jd index a2eaa48..8737280 100644 --- a/docs/html/guide/tutorials/notepad/notepad-ex3.jd +++ b/docs/html/guide/tutorials/notepad/notepad-ex3.jd @@ -1,4 +1,6 @@ page.title=Notepad Exercise 3 +parent.title=Notepad Tutorial +parent.link=index.html @jd:body @@ -354,4 +356,3 @@ the zip file to compare with your own.</p> When you are ready, move on to the <a href="notepad-extra-credit.html">Tutorial Extra Credit</a> exercise, where you can use the Eclipse debugger to examine the life-cycle events as they happen.</p> -<p><a href="index.html">Back to the Tutorial main page...</a></p> diff --git a/docs/html/guide/tutorials/notepad/notepad-extra-credit.jd b/docs/html/guide/tutorials/notepad/notepad-extra-credit.jd index f64e90e..0d59b56 100644 --- a/docs/html/guide/tutorials/notepad/notepad-extra-credit.jd +++ b/docs/html/guide/tutorials/notepad/notepad-extra-credit.jd @@ -1,4 +1,6 @@ -page.title=Tutorial: Extra Credit +page.title=Notepad Extra Credit +parent.title=Notepad Tutorial +parent.link=index.html @jd:body @@ -65,6 +67,4 @@ when.</p> your application development, but also superb profiling support. You can also try using <a href="{@docRoot}guide/developing/tools/traceview.html">Traceview</a> to profile your application. If your application is running too slow, this can help you find the bottlenecks and fix them.</p> -<p><a href="index.html">Back to the Tutorial main -page...</a></p> diff --git a/docs/html/guide/tutorials/views/hello-mapview.jd b/docs/html/guide/tutorials/views/hello-mapview.jd index fcdf056..b0f59de 100644 --- a/docs/html/guide/tutorials/views/hello-mapview.jd +++ b/docs/html/guide/tutorials/views/hello-mapview.jd @@ -43,7 +43,7 @@ First, we'll create a simple Activity that can view and navigate a map. Then we The API key is generated using the MD5 fingerprint of your application certificate. For the purposes of this exercise, you should use the fingerprint of your debug certificate (which cannot be used to release your application for Android devices, but will work while developing). See how to - <a href="{@docRoot}guide/topics/geo/mapkey.html#getdebugfingerprint">generate a fingerprint from your + <a href="{@docRoot}guide/topics/location/geo/mapkey.html#getdebugfingerprint">generate a fingerprint from your debug certificate</a>, then <a href="http://code.google.com/android/maps-api-signup.html">register the certificate</a> to retieve an API key. Insert the API key as the value of the <code>apiKey</code> attribute. If you do not insert a valid diff --git a/docs/html/guide/tutorials/views/index.jd b/docs/html/guide/tutorials/views/index.jd index 6a6ac4b..2248c68 100644 --- a/docs/html/guide/tutorials/views/index.jd +++ b/docs/html/guide/tutorials/views/index.jd @@ -30,67 +30,67 @@ your strings.xml file.</p> <div> <div class="view"> -<a href="hello-linearlayout.html">LinearLayout<br/> -<img src="images/hello-linearlayout.png" height="285" width="200" /></a> +<a href="hello-linearlayout.html">LinearLayout</a><br/> +<a href="hello-linearlayout.html"><img src="images/hello-linearlayout.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-relativelayout.html">RelativeLayout<br/> -<img src="images/hello-relativelayout.png" height="285" width="200" /></a> +<a href="hello-relativelayout.html">RelativeLayout</a><br/> +<a href="hello-relativelayout.html"><img src="images/hello-relativelayout.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-tablelayout.html">TableLayout<br/> -<img src="images/hello-tablelayout.png" height="285" width="200" /></a> +<a href="hello-tablelayout.html">TableLayout</a><br/> +<a href="hello-tablelayout.html"><img src="images/hello-tablelayout.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-datepicker.html">DatePicker<br/> -<img src="images/hello-datepicker.png" height="285" width="200" /></a> +<a href="hello-datepicker.html">DatePicker</a><br/> +<a href="hello-datepicker.html"><img src="images/hello-datepicker.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-timepicker.html">TimePicker<br/> -<img src="images/hello-timepicker.png" height="285" width="200" /></a> +<a href="hello-timepicker.html">TimePicker</a><br/> +<a href="hello-timepicker.html"><img src="images/hello-timepicker.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-formstuff.html">Form Stuff<br/> -<img src="images/hello-formstuff.png" height="285" width="200" /></a> +<a href="hello-formstuff.html">Form Stuff</a><br/> +<a href="hello-formstuff.html"><img src="images/hello-formstuff.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-spinner.html">Spinner<br/> -<img src="images/hello-spinner.png" height="285" width="200" /></a> +<a href="hello-spinner.html">Spinner</a><br/> +<a href="hello-spinner.html"><img src="images/hello-spinner.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-autocomplete.html">AutoComplete<br/> -<img src="images/hello-autocomplete.png" height="285" width="200" /></a> +<a href="hello-autocomplete.html">AutoComplete</a><br/> +<a href="hello-autocomplete.html"><img src="images/hello-autocomplete.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-listview.html">ListView<br/> -<img src="images/hello-listview.png" height="285" width="200" /></a> +<a href="hello-listview.html">ListView</a><br/> +<a href="hello-listview.html"><img src="images/hello-listview.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-gridview.html">GridView<br/> -<img src="images/hello-gridview.png" height="285" width="200" /></a> +<a href="hello-gridview.html">GridView</a><br/> +<a href="hello-gridview.html"><img src="images/hello-gridview.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-gallery.html">Gallery<br/> -<img src="images/hello-gallery.png" height="285" width="200" /></a> +<a href="hello-gallery.html">Gallery</a><br/> +<a href="hello-gallery.html"><img src="images/hello-gallery.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-tabwidget.html">TabWidget<br/> -<img src="images/hello-tabwidget.png" height="285" width="200" /></a> +<a href="hello-tabwidget.html">TabWidget</a><br/> +<a href="hello-tabwidget.html"><img src="images/hello-tabwidget.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-mapview.html">MapView<br/> -<img src="images/hello-mapview.png" height="285" width="200" /></a> +<a href="hello-mapview.html">MapView</a><br/> +<a href="hello-mapview.html"><img src="images/hello-mapview.png" height="285" width="200" /></a> </div> <div class="view"> -<a href="hello-webview.html">WebView<br/> -<img src="images/hello-webview.png" height="285" width="200" /></a> +<a href="hello-webview.html">WebView</a><br/> +<a href="hello-webview.html"><img src="images/hello-webview.png" height="285" width="200" /></a> </div> <!-- |