Intro/tutorial-ex1

From Android中文网

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

目录

[编辑] 记事本练习 1

In this exercise, you will construct a simple notes list that lets the user add new notes but not edit them. The exercise demonstrates:

在这个练习中,你将要创建一个简单的记事本列表,用户可以添加新的记事但是不能编辑他们。这个练习示范了如下内容:

The basics of ListActivities and creating and handling menu options. How to access/store the notes in an SQLite database to store the notes. How to bind data into a ListView using an ArrayAdapter (one of the simplest ways to bind to a ListView). The basics of screen layouts, including how to lay out a list view, how you can add items to the activity menu, and how the activity handles those menu selections. [Exercise 1] [Exercise 2] [Exercise 3] [Extra Credit]

列表活动创建并操作菜单项的基本知识。 怎样在SQLite数据库中存取记事。 怎样将数据绑定到一个使用了数组适配器的列表视图(最简单的一种绑定到列表视图的方式)。 关于屏幕布局,包括怎样布局一个列表视图,怎样将一个项目加入活动的菜单,活动是怎样操作那些菜单选择,这些内容的基础知识。 [Exercise 1] [Exercise 2] [Exercise 3] [Extra Credit]

[编辑] Step 1

第一步 Open up the Notepadv1 project in Eclipse.

在Eclipse中打开Notepadv1项目。

Notepadv1 is a project that is provided as a starting point - it takes care of some of the boilerplate work that you have already seen if you followed the Hello Android tutorial.

Notepadv1项目是一个起点,它关注一些样板性的工作,如果你完成了Hello Android教程,那么你就曾经见过它们。

Right click in the Package Explorer, select Import.../General/Existing Projects into Workspace. Hit the browse button, and navigate to where you copied the three exercise folders, select Notepadv1 and hit OK. You should see Notepadv1 listed in the projects with a check mark next to it. Hit Finish. The exercise project should be open and ready to go in your Eclipse package explorer. If you see an error about AndroidManifest.xml, or some problems related to an Android zip file, right click on the project and select Android Tools->Fix Project Properties from the popup menu (the project is looking in the wrong location for the library file, this will fix it for you).

右击包资源管理器,选择把.../General/Existing Projects导入到工作区。按浏览键,转到你拷贝的那三个练习所在的文件夹,选择Notepadv1然后点OK。你应该看到Notepadv1列在项目表中,并且有个检查标记在它旁边,点完成。练习项目应该已经打开。如果AndroidManisfest.xml 或者Android zip 文件有什么错误,右击项目然后选择Android Tools->Fix Project Properties(项目在错误的路径里查找库文件,上面的操作会替你修复它)。

[编辑] Step 2

Accessing and modifying data

For this exercise, we are just going to use a SQLite database directly to store our data, but in a real application it would be much better to write a proper ContentProvider to encapsulate this behavior instead.

If you are interested, you can find out more about content providers or the whole subject of Storing, Retrieving, and Exposing Data.

访问和修改数据

在这个练习中,我们仅打算直接用SQLite 数据库来存储我们的数据,但是在一个实际的应用程序中,也许写一个合适的内容提供器(Content Provider)来封装这个行为会更好。

如果你感兴趣,你可以找到更多关于内容提供器或者介绍存储,查找,显示数据的整个主题。

Take a look at the DBHelper class — this class is provided to encapsulate data access to a SQLite database that will hold our notes data and allow us to update it.

Typically you would implement this using a ContentProvider, and in fact the full Notepad application included with the SDK does implement such a ContentProvider. However, there is no reason you can't just use your own SQLite database directly as we do here. The main thing to notice about this class is that it takes care of the details of storing, retrieving and updating data in the SQLite database for us. There are methods for retrieving all the rows, retrieving a row based on rowIds, creating a new row, deleting an existing row and updating a row. If you want a quick primer in how to use the SQLite Database for your own applications, either take a look at this class or better yet, look at the full Notepad application included with the SDK in the samples/ folder as the sample uses a ContentProvider.

看一下DBHelper类-它用来封装对SQLite数据库的数据访问,这个数据库将保存我们的记事本数据并且允 许我们更新它。

通常你将利用一个内容提供器来实现,事实上在SDK中包含的那个完整的记事本程序确实实现了这样一个 ContentProvider。不管怎样,没理由不让你直接用自己的SQLite数据,像我们在这里做的一样。最主要 的事是注意这个类是怎样为我们存储,查找,更新SQLite数据库中的数据。对于查找行,基于行id查找, 创建新行,删除已存在的行和更新一行,这里有一些方法。如果你想迅速了解如何在你的程序中使用SQLite数据库的基础知识,或者看一下这个例子中的类,或者更好的,看一下完整的记事本应用程序。它在SDK的samples/目录中,作为一个使用ContentProvider的例子。

[编辑] Step 3

Layouts and activities Most Activities will have a layout associated with them. The layout will be the "face" of the activity to the user. In this case our layout will take over the whole screen and provide a list of notes.

Full screen layouts are not the only option for an Activity however. You might also want to use a floating layout (for example, a dialog or alert), or perhaps you don't need a layout at all (the activity will be invisible to the user unless you specify some kind of layout for it to use).

布局和活动

大多数活动会有一个相联系的布局。布局是活动对用户的直观表现。在这个例子中,我们的布局将占据整个屏幕并提供一个记事列表。

全屏的布局并不是活动的唯一选择。你也许想知道如何用浮动布局(例如,对话框或者警告),或者也许你完全不需要一个布局(这类活动对用户将是不可见的,除非你为它指定了某种布局)

Open the notepad_list.xml file in res/layout and take a look at it:

This is a layout definition file with a default starting point in it, we have provided this as a convenience to get you going quickly.

a.All Android layout files must start with the XML header line:

<?xml version="1.0" encoding="utf-8"?>.

b.Also, the next definition will often (but not always) be a layout definition of some kind, in this case a LinearLayout.
c.Note also that the xml namespace of Android should always be defined in the top level component or layout in the XML so that android: tags can be used through the rest of the file:

xmlns:android="http://schemas.android.com/apk/res/android"

打开res/layout中的notepad_list.xml文件,看一下:

这是一个布局定义文件,其中包含了默认的起始项。我们提供这些,是为了便于你迅速开始

a.所有的Android布局文件必须以XML头为开始:<?xml version="1.0" encoding="utf-8"?>
b.同样,下一条定义通常(但不完全)是一个某种类的布局定义,在这个例子中是LinearLayout.
c.Android的XML名字空间应该总是定义在xml文件中组件或布局的最上级,这样标签"android:"才能用在文件的其余部分:

xmlns:android="http://schemas.android.com/apk/res/android"

[编辑] Step 4

We need to create the layout to hold our list. Add code inside of the LinearLayout tag so the whole file looks like this: (you may have to hit the Source tab in order to edit the XML file)

我们需要创建一个布局来容纳我们的列表。在LinearLayout标签中添加代码,使得这个文件看起来像下面的样子:(你得敲Source tab按钮来编辑XML文件)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

  <ListView id="@id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
  <TextView id="@id/android:empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_notes"/>

</LinearLayout>
  • The ListView and TextView can be thought as two alternative views, only one of which will be displayed at once. ListView will be used when there are notes to be shown, while the TextView (which has a default value of "No Notes Yet!" defined as a string resource, will be displayed if there aren't any notes to display).
  • The @ in the id strings of the ListView and TextView means that the XML parser should parse and expand the rest of the id string and use an ID resource.
  • And, the android:list and android:empty are IDs that are already provided for us by the Android platform, empty is used automatically when no data is provided in the list adapter. The List Adapter knows to look for these names specifically by default. Alternatively you could also choose to change the default empty view used by the List Adapter by using the setEmptyView().More broadly, the android.R class is a set of predefined resources provided for you by the platform, while your project's R class is the set of resources your project has defined. Resources found in the android.R resource class can be used in the XML files by using the android: name space prefix (as we see here).

  • ListView 和TextView可以看做是两个替代的视图,同一时间只有一个可以被显示。ListView可以用在有记事要显示的时候,而TextView(有一个“No Notes Yet!”的字符串资源作为默认值会在没有任何记事的时候显示)。
  • ListView和TextView的id字串中有一个“@”符号,它的意思是XML解释器应当解析并且展开id字串的剩余部分并且利用ID资源。
  • android:list和android:empty是Android平台已经提供给我们的ID,android:empty在list adapter中没有数据时自动提供。List Adapter默认的搜索这些名字。作为替代,你也可以用setEmptyView();更广泛的,Android.R类是平台提供的预定义资源的集合,你项目中的R类是在你项目中预定义的资源集合。在资源类android.R中出现的资源可以通过android:名字空间前缀在XML文件中使用。

[编辑] Step 5

Resources and the R class

The folders under res/ in the Eclipse project are special. There is a specific structure to the folders and files under this folder.

In particular, resources defined in these folders and files will have corresponding entries in the R class allowing them to be easily accessed and used from your application. Furthermore, they will be bundled and deployed as part of the application.

资源和R类

在Eclipse项目res/下的文件夹很特殊。在这个文件夹下的子文件夹和文件有特定的结构。

尤其,定义在这些文件夹和文件里的资源会在R类中有相应的入口。这样你的程序就可以轻松的访问到这些资源。更进一步的,它们会被绑定,作为程序的一部分。

To make a list view, we also need to define a view for each row in the list:

  • Create a new file under res/layout called notes_row.xml.
  • Add the following contents (note: again the xml header is used, and the first node defines the Android xml namespace)
<?xml version="1.0" encoding="utf-8"?>
<TextView id="@+id/text1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
  • This is the view that will be used for each notes title row — it has only one text field in it.
  • In this case we create a new id called text1. The + after the @ in the id string indicates that the id should be automatically created if it does not already exist, so we are defining text1 on the fly and then using it.
  • After saving this file, open the R.java class in the project and look at it, you should see new definitions for notes_row and text1 (our new definitions) meaning we can now gain access to these from the our code.

要产生一个列表视图,我们需要定义表中各行的显示:

  • 在res/layout下创建一个名为notes_row.xml的文件
  • 添加如下的内容(注:xml头又一次被用到了,并且第一个节点定义了Android xml名字空间)
<?xml version="1.0" encoding="utf-8"?>
<TextView id="@+id/text1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
  • 每一行的标题将用到这个视图-它仅有一个文字区域。
  • 在这个例子中,我们创建了一个叫text1的新id。在id字串中+号跟在@号之后,显示了这个id如果不存在,则应当自动创建。因此我们定义了一个悬空的text1,然后使用它。
  • 保存文件后,打开项目中的R.java类,你应该看到notes_row和text1的新定义(我们的新定义),这意味着,我们可以从我们的代码中获得访问。

[编辑] Step 6

Next, open the Notepadv1 class in the source. We are going to alter this class to become a list adapter and display our notes, and also allow us to add new notes

Notepadv1 will be a subclass of Activity called a ListActivity, which has extra functionality to accommodate the kinds of things you might want to do with a list, for example: displaying an arbitrary number of list items in rows on the screen, moving through the list items, and allowing them to be selected.

Take a look through the existing code in Notepadv1 class. There are some constant definitions at the top, followed by a private field we will use to create numbered note titles, and some overrides of methods from the superclass.


然后,打开源码中的Notepadv1类。我们将要替换这个类,成为列表适配器来显示我们的记事,同时允许我们添加新的记事。

Notepadv1将成为Activity的一个子类,称为ListActivity,它拥有一些适合做与列表相关的额外功能,例如:在屏幕上按行显示列表项的数字,在列表项中移动,允许他们被选择。

看一下Notepadv1类中的现有代码。在最上面有一些常量定义,接着的私有区域里我们将创建数字形式的记事标题,并且还有一些从超类重载的方法。

[编辑] Step 7

Change the inheritance of Notepadv1 from Activity to ListActivity:

public class Notepadv1 extends ListActivity

Note: you will have to import ListActivity into the Notepadv1 class using Eclipse, ctrl-shift-O on Windows or Linux, or cmd-shift-O on the Mac (organize imports) will do this for you.


将Notepadv1的父类从Activity改为ListActivity:

public class Notepadv1 extends ListActivity

注:你必须用Eclipse把ListActivity导入到Notepadv1类中,在Windows或Linux按crtl-shift-O,或者在Mac下按cmd-shift-O。

[编辑] Step 8

There are already three override methods defined: onCreate, onCreateOptionsMenu and onOptionsItemSelected, we need to fill these out:

  • onCreate() is called when the activity is started — it is a little like the "main" method for the activity. We use this to set up resources and state for the activity when it is running
  • onCreateOptionsMenu() is used to populate the menu for the activity. This is shown when the user hits the menu button, and has a list of options they can select (like "Create Note")
  • onOptionsItemSelected() is the other half of the menu equation, it is used to handle events generated from the menu (e.g. when the user selects the "Create Note" item).

这里定义了三个重载方法:onCreate,onCreateOptionsMenu和onOptionsItemSelected,我们把需要的内容详细说明一下:

  • onCreate()在活动开始的时候被调用-它有一点像activity的"main"方法。我们用这个函数在活动运行的时候为它设置资源和状态。
  • onCreateOptionsMenu()用来为活动产生一个菜单。当使用者点击menu按钮的时候,它会显示,并且有一列可以选择的选项(像“Create Note”)
  • onOptionsItemSelected()是菜单等式中(菜单处理过程)的另一半,它用来处理由菜单产生的事件(例如.当用户选择了“Create Note”选项)

[编辑] Step 9

Fill out the body of the onCreate() method.

Here we will set the title for the activity (shown at the top of the screen), use the notepad_list layout we have created for the activity display contents, set up the DBHelper instance we will use to access notes data, then populate the list with the available note titles:

  1. call super() with the icicle parameter passed into our method
  2. setContentView to R.layout.notepad_list
  3. Create a new private class field called dbHelper of class DBHelper (before the onCreate method)
  4. Back in the onCreate method, construct a DBHelper instance — assign to the dbHelper field (note, you must pass this into the constructor for DBHelper)
  5. Finally, call a new method -fillData()- gets the data and populates it using the helper, we haven't defined it yet
  6. onCreate() should now look like this:
   @Override
   public void onCreate(Bundle icicle)
   {
       super.onCreate(icicle);
       setContentView(R.layout.notepad_list);
       dbHelper = new DBHelper(this);
       fillData();
   }

And remember to add the DBHelper field definition (right under the noteNumber definition):

   private DBHelper dbHelper;

详细说明onCreate()方法的主体。

在这儿,我们将要为活动设定一个名称(显示在屏幕的最上面),利用我们先前为活动创建的notepad_list布局来显示内容,建立DBHelper实例来访问记事数据,然后产生带有有效记事标题的列表:

  1. 在我们的方法中,调用带有icicle参数的super()函数
  2. setContentView到R.layout.notepad_list
  3. 在类中新建一个叫dbHelper的私有域,它是DBHelper的实例(在OnCreate 方法之前)
  4. 回到onCreate方法,新建一个DBHelper实例-assign到dbHelper区域(注,你必须为DBHelper的构造函数传递一个this参数)
  5. 最后,调用一个新方法-fillData()-利用helper获取并产生数据,我们现在还没有定义这个函数。
  6. onCreate()函数应该像这样:
@Override
   public void onCreate(Bundle icicle)
   {
       super.onCreate(icicle);
       setContentView(R.layout.notepad_list);
       dbHelper = new DBHelper(this);
       fillData();
   }

记住添加DBHelper的定义(在noteNumber定义的下面):

 private DBHelper dbHelper;

[编辑] Step 10

More on menus

The notepad application we are constructing only scratches the surface with menus.

You can also add shortcut keys for menu items, create submenus and even add menu items to other applications!.

菜单的更多解释

我们构建的记事本程序仅仅涉及了菜单的表面。

你可以为菜单项添加快捷键,创造子菜单甚至将菜单添加到别的应用程序中

Fill out the body of the onCreateOptionsMenu() method.

We are going to add just one menu item for now, "Add Item", using a string we will create in strings.xml, and defined with a constant we will create at the top of the class to identify the Add Item operation.

  1. In strings.xml resource (under res/values), add a new string for menu_insert with text "Add Item" <string name="menu_insert">Add Item</string>, then save the file
  2. Also, you need a menu position constant at the top of the Notepadv1 class (right under the KEY_BODY definition): public static final int INSERT_ID = Menu.FIRST;
  3. In the onCreateOptionsMenu() method, add the menu item. Also take care of the result of the super call being returned. The whole method should now look like this:
   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
       boolean result = super.onCreateOptionsMenu(menu);
       menu.add(0, INSERT_ID, R.string.menu_insert);
       return result;
   }

onCreateOptionMenu()方法的主体

我们现在要添加一个菜单项,“Add Item”,它会用到我们在strings.xml中创建的字符串,并且用到一个常量定义,这个常量我们在类的顶部创建来标志Add项的操作。

  1. 在strings.xml资源中(在res/values下),为menu_insert添加一个新的字符创“Add Item”<string name="menu_insert">Add Item</string>,然后保存文件
  2. 同时,你需要在Notepadv1类的顶部定义一个菜单位置常量(在KEY_BODY的定义下面)public static final int INSERT_ID=Menu.FIRST;
  3. 在onCreateOptionsMenu()方法中,添加一个菜单项。同时注意super调用的返回值结果。整个方法应该看起来像下面的样子:
@Override
   public boolean onCreateOptionsMenu(Menu menu) {
       boolean result = super.onCreateOptionsMenu(menu);
       menu.add(0, INSERT_ID, R.string.menu_insert);
       return result;
   }

[编辑] Step 11

Fill out the body of the onOptionsItemSelected() method:

This is going to handle our new "Add Note" menu item. When this is selected the onOptionsItemSelected() method will be called with the item.getId() set to INSERT_ID (the constant we used to identify the menu item). We can detect this, and take the appropriate actions:

  1. The super.onOptionsItemSelected(item) method call goes at the end of this method — we want to catch our events first!
  2. Switch statement on item.getId()
  3. case INSERT_ID:
  4. calls new method createNote()
  5. break at the end of the case
  6. return the result of the superclass onOptionsItemSelected() method at the end
  7. The whole onOptionsItemSelect() method should now look like this:
   @Override
   public boolean onOptionsItemSelected(Item item) {
       switch (item.getId()) {
       case INSERT_ID:
           createNote();
           break;
       }
      
       return super.onOptionsItemSelected(item);
   }

onOptionsItemSelected()方法:

这个方法将要处理我们新的“添加记事”菜单项。当选中这个菜单项时,onOptionsItemSelected()方

法就将被调用,同时item.getId()的值会被设为INSERT_ID(我们用这个常量来标志菜单项)。我们能

检查这个,然后选择适当的动作:

  1. super.onOptionsItemSelected(item)方法出现在这个方法的最后-我们想要先抓取我们的事件!
  2. 在item.getId()上的选择语句。
  3. INSERT_ID项。
  4. 调用新方法createNote()
  5. 在case的结尾用break
  6. 在结束的时候返回超类onOptionsItemSelected()方法的返回值
  7. 整个onOptionsItemSelect()方法看起来应该如下:
@Override
   public boolean onOptionsItemSelected(Item item) {
       switch (item.getId()) {
       case INSERT_ID:
           createNote();
           break;
       }
      
       return super.onOptionsItemSelected(item);
   }

[编辑] Step 12

Add a new createNote() method:

In this first version of our application, createNote() is not going to be very useful. We will simply create a new note with a title assigned to it based on a counter ("Note 1", "Note 2"...) and with an empty body. At present we have no way of editing the contents of a note, so for now we will have to be content making one with some default values:

  1. String noteName = "Note " + noteNumber++; (Construct the name using "Note" and the counter we have defined in the class)
  2. Call dbHelper.createRow() using noteName as the title and "" for the body
  3. Call fillData() method again after adding (inefficient but simple)
  4. The whole createNote() method should look like this:
   private void createNote() {
       String noteName = "Note " + noteNumber++;
       dbHelper.createRow(noteName, "");
       fillData();
   }

添加一个createNote()方法: 在我们应用程序的这个第一版里,createNote()不会很有用。我们只是简单的创建一个带有标题的记事,

这个标题被赋值为(“Note1”,“Note2”。。。)这类基于计数的东东,但是记事的内容为空。现在我

们还不能修改记事的内容,所以我们现在只能满足于一些默认值:

  1. String noteName="Note"+noteNumber++;(用“Note”来构造名字并且用到我们已经在类中定义过的计数器)
  2. 调用dbHelper.createRow(),使用noteName作为标题,“”为内容
  3. 在添加之后再调用一次fillData()方法(一个低效但是简单的方法)
  4. 整个createNote()方法看起来应该像这样:
private void createNote() {
       String noteName = "Note " + noteNumber++;
       dbHelper.createRow(noteName, "");
       fillData();
   }

[编辑] Step 13

List adapters

Our example uses a very simple array adapter which binds an array or list of items into a ListView. More commonly in Android, List Adapters go hand in hand with ContentProviders, and this is also a very easy way to use lists.

To bind a ContentProvider to a ListView you can use a android.widget.SimpleCursorAdapter to bind data from a ContentProvider into a ListView

列表适配器

我们的例子使用了一个非常简单的数组适配器,它将一个项目的数组或列表添加至列表视图。在Android中更常见的是,列表适配器和ContenProviders一起运行,并且这也是列表的一种非常简单的用法。

将ContentProvider捆绑至ListView,你可以用android.widget.SimpleCursorAdapter。

Define the fillData() method. This is fairly long:

This method uses ArrayAdapter, which is the simplest way of putting data into a ListView. ArrayAdapter takes either a List or an array of Strings, and binds them into a text view provided in the layout defined for the list row (this is the text1 field in our notes_row.xml layout). The method simply obtains a list of notes from the database helper, constructs a List of Strings using the title strings from each row, and then creates an ArrayAdapter out of those items and bound to use the notes_row we defined.

    private void fillData() {
        // We need a list of strings for the list items
        List<String> items = new ArrayList<String>();

        // Get all of the rows from the database and create the item list
        List<Row> rows = dbHelper.fetchAllRows();
        for (Row row : rows) {
            items.add(row.title);
        }
        
        // Now create an array adapter and set it to display using our row
        ArrayAdapter<String> notes =
            new ArrayAdapter<String>(this, R.layout.notes_row, items);
        setListAdapter(notes);
        
    }
  1. ArrayAdapter needs a List of Strings (List<String>) containing the items to display
  2. The data is read out of the database as rows, and the title field from each row is used to populate the list of strings
  3. We specify the notes_row view we created as the receptacle for the data
  4. If you get compiler errors about classes not being found, ctrl-shift-O or (cmd-shift-O on the mac) to organize imports.
 Note: that for this exercise we use an ArrayAdapter, this is not a very scalable solution and more typically a SimpleCursorAdapter would be used with a ContentProvider or at least a Cursor returned from a query. See the sidebar on List Adapters for more information.

定义fillData()方法。这个方法很长:

这个方法使用了ArrayAdapter,它是将数据放入ListView的最简单方法。ArrayAdapter读取一个列表或者字串数组,并且将他们绑定到一个文本视图,在布局中提供了这个为列表行定义的文本视图(在我们的notes_row.xml布局文件中的text1域)。这个方法简单的从database helper中获取一列记事,利用从每行得到的标题字串构造了一个字符串列表,然后通过这些items创建一个ArrayAdapter,并使用我们定义过的notes_row

  1. 数组适配器需要一个字符串列表(List<String>)来包含要显示的。
  2. 数据从数据库中按行读出,每行的标题域用来产生字符串列表。
  3. 我们指定notes_row视图,作为数据容器。
  4. 如果有关于未找到类的错误,ctrl-shift-O(在mac上用cmd-shift-O)来组织导入。

注:在这个练习中我们使用了ArrayAdapter,这并不是好的解决方案,更典型的,一个SimpleCursorAdapter应该和ContenProvider一起用或者至少是一个从查询返回的Cursor。看侧边的列表适配器获得更多信息。

[编辑] Step 14

Run it!

  1. Right click on the Notepadv1 project
  2. From the popup menu, select Run As -> Android Application
  3. If you see a dialog come up, select Android Launcher as the way of running the application (you can also use the link near the top of the dialog to set this as your default for the workspace, this is recommended as it will stop the plugin from asking you this every time)
  4. Add new notes by hitting the menu button and selecting Add Item from the menu

运行!

  1. 右击Notepadv1项目
  2. 在弹出菜单中,选择Run As->Android Application
  3. 如果你看见出现一个对话框,选择Android Launcher的方式去运行程序(你同样可以用对话框顶部的链接,把这个设置为你工作空间的默认属性,推荐这样做,它可以避免插件每次都询问你同样的问题)
  4. 单击菜单按钮,选择Add Item 来添加记事

[编辑] Solution and Next Steps

You can see the solution to this class in Notepadv1Solution from the zip file to compare with your own.

Once you are ready, move on to Tutorial Exercise 2 to add the ability to create, edit and delete notes.

Back to the Tutorial main page...


方案和下一步

你可以在zip文件Notepadv1Solution中找到这个类的解决方案,对照一下你自己的。一旦你准备好,继续入门指引练习2为程序添加新建,编辑删除记事的能力。 返回入门指引首页。

Personal tools