Android记事本【1】

来源:互联网 发布:js array lastindexof 编辑:程序博客网 时间:2024/05/29 08:52

这个程序是developer.android.com里面的一个例子,网上有源代码。姑且拿来做个练习,抛砖引玉。

 

假设您已经有一点Android开发的基础知识,并且配置好开发环境。

 

一、首先让我们对本次开发做个简单的总体设计:

 

    界面及交互流程:


SQLite数据表设计:

 

 

代码结构设计:

src/notepad.example.notepad/

NotepadActivity.java

NoteEditActivity.java

NotesDbAdapter.java

res/drawable/icon.png

res/layout/

notes_list.xml

notes_row.xml

note_edit.xml

 

二、先有个入口界面:

1.新建Android工程,程序命名为:Notepad,工程名为:Notepad,Package名为:com.example.notepad。Build SDK选Android 2.2, Minimum Required SDK 选2.2。一路”NEXT”,最后Activity名为:NotepadActivity,布局文件名为:main.xml。

2.准备工作做好了。进入程序首先是一个列表页面,用于展示已添加的事项的标题,并能显示添加新事项的按钮。

首先让我们的NotepadActivity继承ListActivity,引入“android.app.ListActivity”。

在res\lay_out下创建个布局文件notes_list.xml。

代码如下:

 

<?xmlversion="1.0"encoding="utf-8"?>

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:background="@color/bgcolor"

    android:orientation="vertical">

 

    <ListView

        android:id="@+id/android:list"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:textColor="@color/textcolor"

        android:textSize="16pt" >

    </ListView>

 

    <TextView

        android:id="@+id/android:empty"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="@string/no_notes"

        android:textColor="@color/textcolor"

        android:textSize="16pt" >

    </TextView>

 

</LinearLayout>

 

values/string.xml里定义几个标红的字符串常量值,值可以随意思指定。

NotepadActivity.java中将setContentVie函数的参数改为R.layout.notes_list

 

右键单击工程,RunAs --> 1. Android Application,试着跑一下,如下图。


下节我们尝试增加个添加按钮,加入新的记事。

原创粉丝点击