写在前面
课程作业需要,于是忙活好几天抄了一个简单的记事本,使用已学内容包括Android UI布局,Activity的跳转,SQLite数据库。
开发环境:Android Studio
目录
一.界面预览
主界面
编辑界面
长按删除
二.基本实现
布局实现代码
初始界面功能,最上方标题下为用户创建的各条记录,点击进行修改,长按删除,最下方有添加笔记按钮进行笔记的增加操作。实现的布局文件有初始界面activity_main.xml(里面包含可以以列表的形式展示数据内容的ListView控件)、note_item(ListView对应的item布局,以显示每个条目信息)、note_editor(新建文本编辑界面)、activity_show(文本修改界面)
activity_main.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eaeaea"
android:orientation="vertical"
tools:context=".MainActivity" >
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Notepad"
android:textSize="20sp"
android:textStyle="bold"
android:background="#efdede"
android:paddingTop="10dp"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:gravity="left">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eaeaea"
android:layout_weight="1">
android:id="@+id/lv_note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
android:id="@+id/btn_add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="10dp"
android:textSize="20sp"
android:text="添加笔记"/>
note_item.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:lines="1"
android:text=""
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge"/>
android:id="@+id/tv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:lines="1"/>
android:id="@+id/tv_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="" />
note_editor.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eaeaea"
android:orientation="vertical">
android:id="@+id/et_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="请输入标题">
android:id="@+id/edit_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#d7d5d5"
android:gravity="right"
android:textSize="10sp"/>
android:id="@+id/et_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:hint="请输入内容"
android:gravity="left"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center">
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"