赞
踩
(1)业务需求分析:分析潜在客户需要什么产品或服务
(2)架构分析:分析所做的产品或服务需要什么功能及实现方式并画出功能结构图,记事本案例如下
(3)数据库类设计分析:数据库设计是项目开发中非常关键的一个环节。同样在记事本案例中也至关重要,我们通过数据库表(Note)进行增删改查操作,记事本的数据表如下所示
字段名 | 数据类型 | 字段名 | 数据类型 |
---|---|---|---|
id | integer | 是 | 编号 |
content | text | 否 | 事件内容 |
notetime | text | 否 | 保存事件的时间 |
(4)界面需求分析:友好的界面在移动平台开发中非常重要,也是用户使用软件的先决条件。记事本案例分为3个界面,分别为记事本界面、添加界面和修改界面
记事本界面包含添加按钮和记录列表,点击后会跳转到添加界面,界面标题为添加记录,也可在该界面清除和保存编辑的内容。当点击记事本界面中的Item时,会跳转到修改记录界面,界面标题为修改记录,在该界面中可以查看和修改已保存的记录内容,也可清除和保存编辑的内容
(1)创建项目后将Activity名称设置为NotepadActivity,布局文件为activity_notepad并将所需素材add.png(添加按钮),save_note.png(保存按钮),delete.png(删除按钮),back.png(返回按钮)导入drawable文件夹中,如下
上面添加按钮右边还有个返回按钮图片是白色的
(2)编写activity_notepad.xml布局文件,放置一个TextView控件用于显示界面标题,一个ListView控件用于显示记录列表,一个ImageView控件用于显示添加按钮的图片
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fefefe" tools:context=".NotepadActivity"> <TextView android:layout_width="match_parent" android:layout_height="45dp" android:gravity="center" android:text="记事本" android:textSize="20sp" android:textColor="@android:color/white" android:textStyle="bold" android:background="#fb7a6a" android:id="@+id/note_name" /> <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/listview" android:cacheColorHint="#00000000" android:divider="#B4B4B4" android:dividerHeight="1dp" android:fadingEdge="none" android:listSelector="#00000000" android:scrollbars="none" android:layout_below="@id/note_name" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/add" android:id="@+id/add" android:layout_marginBottom="30dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /> </RelativeLayout>
(3)修改清单文件
项目创建后所有界面都有一个默认的标题栏,该标题栏不太美观,因此需要在清单文件(AndroidManifest.xml)中的<application>
标签中修改android:theme属性
android:theme="@style/Theme.AppCompat.NoActionBar"
(4)搭建记事本界面Item布局
在res/layout文件夹中,创建一个布局文件notepad_item_layout.xml,在其中放置两个TextView控件,分别用来显示记录的部分内容与保存记录的时间
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingLeft="12dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/item_content" android:maxLines="2" android:ellipsize="end" android:lineSpacingExtra="3dp" android:paddingTop="10dp" android:textColor="@android:color/black" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/item_time" android:textColor="#fb7a6a" android:paddingTop="5dp" android:paddingBottom="7dp" /> </LinearLayout>
(5)封装记录信息实体类
由于记事本中的每个记录都会有记录内容和保存记录的时间属性,因此需要创建一个NotepadBean用于存放这些属性。选中你所创建的项目的包,右击选择New>Package,创建一个bean包,在该包中创建一个NotepadBean类,该类中定义记录信息的所有属性
package com.example.notepad.bean; public class NotepadBean { private String id; private String notepadContent; private String notepadTime; public String getId(){ return id; } public void setId(String id){ this.id=id; } public String getNotepadContent(){ return notepadContent; } public void setNotepadContent(String notepadContent){ this.notepadContent=notepadContent; } public String getNotepadTime(){ return notepadTime
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。