当前位置: 首页 > news >正文

中国航发网上商城宁波网站优化体验

中国航发网上商城,宁波网站优化体验,永川集团网站建设,房产官网查询系统用Android手撸一个简易的个人记账系统⛱️序言#x1f4cb;一、系统结构设计Design1. 需求分析2. 数据库设计3. 界面设计4. 过程设计#x1f4d8;二、编码阶段Coding1. 项目结构#x1f5c2;️#xff08;1#xff09;文件目录#xff08;2#xff09;AndroidManifest.x… 用Android手撸一个简易的个人记账系统⛱️序言一、系统结构设计Design1. 需求分析2. 数据库设计3. 界面设计4. 过程设计二、编码阶段Coding1. 项目结构️1文件目录2AndroidManifest.xml3Activity类解读4XML解读2. 静态页面⌛1用户登录页面activity_main.xml2用户注册页面activity_register.xml3用户个人中心页面activity_user_center.xml4用户搜索记录页面activity_search_record.xml5收支管理页面activity_manage.xml6列表数据记录record_item_layout.xml3. 逻辑结构1DBHelper类2MainActivity类3RegisterActivity类4UserCenterActivity类5SearchRecordActivity类6ManageActivity类7User类三、运行结果Result四、结束语彩蛋 One More Thing(:不合理设计(:番外篇⛱️序言 前段时间期末周这学期有一门课叫移动应用开发这门课的期末作业是用 Android 写一个个人记账管理系统。 Android 的前台是用 xml 实现后台是用 java 实现。于是对这两门语言不太熟悉的周一开始了漫漫长路的摸索之旅。 接下来就来讲解如何从0到1实现一个简易的个人记账系统。 一起来学习⑧~ 温馨小提示 第二部分的编码阶段代码较多可直接滑到第三部分看运行效果并到第四部分克隆github仓库代码阅读体验更加~ 一、系统结构设计Design 1. 需求分析 首先我们先来看下老师的需求 设计和实现一个类似个人财务管理的 Android APP 数据库采用 SQLite 也可以直接访问 Web 端 MySQL 数据库、或提供 Web 接口访问 MySQL 数据库。 APP应具备以下功能 用户注册和登录这类 APP 一般面对个人用户不需要分类别收入和支出管理单条收支记录的添加、删除和修改收入和支出每一条记录至少包括日期、类型、金额和说明。收入和支出查询根据时间段、类别等进行查询收入和支出统计例如某个月、某个星期或指定时间段的总收支其他要求界面设计应尽量美观可以添加一些图片或背景。 基于以上需求周一对所要实现的功能进行了整理。请看下方思维导图 2. 数据库设计 分析完成之后接下来开始设计数据库。详情见下方思维导图 因为功能较为简单所以数据库只设计了两张表。 3. 界面设计 设计完数据库之后开始楷模润色该 APP 的界面。基于本次课题需求周一设计了5个界面。接下来先来看 App 的具体界面设计 看完五个界面所需要的内容之后接下来我们来对它进行原型绘制。请看下图 现在原型图设计完毕。我们接着设计高保真 App 界面。请看下图 4. 过程设计 好了看完原型图之后我们是不是该来想想页面与页面之间是怎么进行交互的呢 因此现在我们来对整个过程进行设计。详情见下方思维导图 二、编码阶段Coding 1. 项目结构️ 1文件目录 先来看项目的文件目录详情看下图 2AndroidManifest.xml 接下来附上 AndroidManifest.xml 的代码具体代码如下 ?xml version1.0 encodingutf-8? manifest xmlns:androidhttp://schemas.android.com/apk/res/androidpackagecom.financial.managementapplicationandroid:allowBackuptrueandroid:iconmipmap/ic_launcherandroid:label个人财务管理Appandroid:roundIconmipmap/ic_launcherandroid:supportsRtltrueandroid:themestyle/Theme.Finalactivity android:namecom.financial.management.ManageActivity/activityactivity android:namecom.financial.management.SearchRecordActivity /activity android:namecom.financial.management.RegisterActivity/activity android:namecom.financial.management.UserCenterActivity /activity android:namecom.financial.management.MainActivityintent-filteraction android:nameandroid.intent.action.MAIN /category android:nameandroid.intent.category.LAUNCHER //intent-filter/activity/application/manifest3Activity类解读 看完上面两个内容之后接下来是Activity类的解读时间。详情见下表 文件名作用MainActivity用户登录页面Activity用户可以进行登录。RegisterActivity用户注册页面Activity用户可以进行注册。UserCenterActivity个人中心Activity对应用户个人中心的4个按钮进行功能编写实现用户收支管理、查看收支、收支统计、退出登录四大功能。ManageActivity收支管理Activity对用户的收入和支出进行管理。SearchRecordActivity查询收支Activity通过条件对数据库中的数据进行查询得出用户想要查询的收支结果。DBHelper创建数据库表和数据库数据同时实现与数据库操作相关的登录和注册方法。User用户类Activity用于获取用户ID以及密码。 4XML解读 解读完 Activity 类之后现在来对 XML 的各个文件进行介绍。详情见下表 文件名作用activity_main.xml用户登录页面用户通过输入账号和密码进行登录操作。activity_register.xml用户注册页面用户通过输入账号和密码进行注册操作。activity_user_center.xml个人中心页面当用户登录成功以后进行个人中心页面。个人中心实现收支管理、查看收支、收支统计、退出登录四大功能。activity_search_record.xml通过选择年份月份来进行查询该年该月份的各个收入支出详情并且计算总金额以及根据类别来计算该类别的总金额。activity_manage.xml用户对自己的日常开销进行收支管理可以进行添加、删除和修改等操作。record_item_layout.xml用来存储列表的传输数据 到这里大家先对待会要编写的 Activity 类和 XML 文件所要展示的功能先进行一番了解。 2. 静态页面⌛ 现在我们到了真正的编码阶段啦如果是按照我的编码习惯的话我一般会先把静态页面进行构建并把一些需要预留的id等等信息给先处理好方便后面写业务逻辑时可以直接进行绑定。 针对以上6个静态页面下面将进行代码编写。 1用户登录页面activity_main.xml activity_main.xml 是用户登录页面当用户通过输入账号和密码时可以进行登录操作。具体代码如下 ?xml version1.0 encodingutf-8? androidx.constraintlayout.widget.ConstraintLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.MainActivityLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticalandroid:gravitycenter_horizontalapp:layout_constraintLeft_toLeftOfparentapp:layout_constraintTop_toTopOfparentTextViewandroid:idid/textView1android:layout_width360dpandroid:layout_height360dpandroid:gravitycenterandroid:backgrounddrawable/login_logoandroid:textColor#fffandroid:textSize24dpandroid:layout_marginTop-30dpandroid:layout_marginHorizontal45dp/TextViewandroid:idid/textViewandroid:layout_widthmatch_parentandroid:layout_height60dpandroid:gravitycenter|center_horizontalandroid:text用户登录android:textColor#5768C5android:textSize20dpandroid:layout_marginTop-60dp/LinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationhorizontalandroid:paddingHorizontal20dpandroid:paddingVertical10dpImageViewandroid:idid/imageView3android:layout_width50dpandroid:layout_height50dpandroid:layout_weight0app:srcCompatdrawable/account /EditTextandroid:idid/edt_uidandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight2android:ems10android:hint请输入您的用户名android:inputTypetextPersonName //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_weight0android:orientationhorizontalandroid:paddingHorizontal20dpandroid:paddingVertical10dpImageViewandroid:idid/imageView4android:layout_width50dpandroid:layout_height50dpandroid:layout_weight0app:srcCompatdrawable/password /EditTextandroid:idid/edt_upwdandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:ems10android:hint请输入您的密码android:inputTypetextPassword //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_height80dpandroid:gravitycenterandroid:orientationhorizontalandroid:paddingHorizontal60dpButtonandroid:idid/btn_loginandroid:layout_width100dpandroid:layout_height60dpandroid:layout_weight1android:text登录android:textSize18dpapp:backgroundTint#4757AEapp:cornerRadius50dp //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationverticalButtonandroid:idid/btn_registerandroid:layout_widthmatch_parentandroid:layout_height40dpandroid:gravitycenterandroid:text还没有账号现在注册android:textColor#888282android:textColorHint#FFFFFFFFandroid:backgroundTint#FFFFFFFFandroid:color#FFFFFF//LinearLayoutTextViewandroid:layout_widthmatch_parentandroid:layout_height20dpandroid:background#FFFFFFandroid:layout_marginTop-10dp//LinearLayout/androidx.constraintlayout.widget.ConstraintLayout2用户注册页面activity_register.xml activity_register.xml 是用户注册页面用户通过输入账号和密码可以进行注册操作。具体代码如下 ?xml version1.0 encodingutf-8? androidx.constraintlayout.widget.ConstraintLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.RegisterActivityLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticalandroid:gravitycenterapp:layout_constraintTop_toTopOfparentTextViewandroid:idid/textView10android:layout_width220dpandroid:layout_height220dpandroid:backgrounddrawable/register_logoandroid:gravitycenterandroid:textColor#FFEB3Bandroid:layout_marginBottom20dp/TextViewandroid:idid/textView5android:layout_widthmatch_parentandroid:layout_height50dpandroid:gravitycenterandroid:text用户注册android:textColor#0C6BC2android:textSize22sp /LinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationhorizontalandroid:paddingHorizontal20dpandroid:layout_marginTop10dpTextViewandroid:idid/textView7android:layout_widthwrap_contentandroid:layout_height45dpandroid:layout_weight0android:text账 号: android:textColor#0C6BC2android:textSize22sp /EditTextandroid:idid/edt_ridandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:ems10android:hint请输入需要注册的账号android:inputTypetextPersonName //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationhorizontalandroid:paddingHorizontal20dpandroid:layout_marginVertical15dpTextViewandroid:idid/textView8android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight0android:text密 码: android:textColor#0C6BC2android:textSize22sp /EditTextandroid:idid/edt_rpwdandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:ems10android:hint请输入密码android:inputTypetextPassword //LinearLayoutButtonandroid:idid/btn_registeruserandroid:layout_width260dpandroid:layout_height60dpandroid:layout_gravitycenterandroid:layout_marginVertical20dpandroid:background#2D6C2Fandroid:gravitycenterandroid:text注册android:textSize22spapp:backgroundTint#1C8DE6 //LinearLayout /androidx.constraintlayout.widget.ConstraintLayout3用户个人中心页面activity_user_center.xml 现在来到了个人中心页面。在个人中心页面当中将会显示具体的用户名。同时 有四个按钮入口分别是收支管理查看收支退出登录和收支统计。来看下具体代码实现 ?xml version1.0 encodingutf-8? androidx.constraintlayout.widget.ConstraintLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.UserCenterActivityLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticalapp:layout_constraintLeft_toLeftOfparentapp:layout_constraintTop_toTopOfparentLinearLayoutandroid:layout_widthmatch_parentandroid:layout_height120dpandroid:orientationhorizontalandroid:gravitycenterImageViewandroid:idid/imageViewandroid:layout_width60dpandroid:layout_height60dpapp:srcCompatdrawable/girlandroid:layout_marginHorizontal30dp/TextViewandroid:idid/tv_welcomeandroid:layout_widthwrap_contentandroid:layout_heightmatch_parentandroid:layout_weight1android:gravitycenter|leftandroid:textColor#4F92CFandroid:textSize24sp //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationhorizontalandroid:gravitycenter_horizontalandroid:layout_marginTop40dpLinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginHorizontal20dpandroid:background#FFFFFFandroid:gravitycenter_horizontalandroid:orientationverticalandroid:padding24dpandroid:elevation10dpapp:cornerRadius30dpImageViewandroid:idid/btn_recordmanageandroid:layout_width60dpandroid:layout_height60dpapp:srcCompatdrawable/revenue /TextViewandroid:idid/textView17android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginTop20dpandroid:text收支管理android:textColor#252020android:textSize18sp //LinearLayoutLinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:orientationverticalandroid:gravitycenter_horizontalandroid:layout_marginHorizontal20dpandroid:background#FFFFFFandroid:padding24dpandroid:elevation10dpapp:cornerRadius30dpImageViewandroid:idid/btn_searchrecordandroid:layout_width60dpandroid:layout_height60dpapp:srcCompatdrawable/look /TextViewandroid:idid/textView22android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text查看收支android:textColor#FF252020android:textSize18spandroid:layout_marginTop20dp//LinearLayout/LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationhorizontalandroid:gravitycenter_horizontalandroid:layout_marginVertical30dpLinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:orientationverticalandroid:gravitycenter_horizontalandroid:layout_marginHorizontal20dpandroid:background#FFFFFFandroid:padding24dpandroid:elevation10dpapp:cornerRadius30dpImageViewandroid:idid/btn_exitandroid:layout_width60dpandroid:layout_height60dpapp:srcCompatdrawable/exit /TextViewandroid:idid/textView4android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:gravitycenterandroid:text退出登录android:textColor#FF252020android:textSize18spandroid:layout_marginTop20dp//LinearLayoutLinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:orientationverticalandroid:gravitycenter_horizontalandroid:layout_marginHorizontal20dpandroid:background#FFFFFFandroid:padding24dpandroid:elevation10dpapp:cornerRadius30dpImageViewandroid:idid/btn_calcmoneyandroid:layout_width60dpandroid:layout_height60dpapp:srcCompatdrawable/statics /TextViewandroid:idid/textView23android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text收支统计android:textColor#FF252020android:textSize18spandroid:layout_marginTop20dp//LinearLayout/LinearLayout/LinearLayout /androidx.constraintlayout.widget.ConstraintLayout4用户搜索记录页面activity_search_record.xml 用户可以通过选择年份月份和筛选类型点击搜索来查询该年该月份的各个收入和支出的详情同时在该时间点和该筛选类型下点击计算可以对总金额进行计算。下面附上具体代码实现 ?xml version1.0 encodingutf-8? androidx.constraintlayout.widget.ConstraintLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightwrap_contenttools:context.SearchRecordActivityLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticalapp:layout_constraintLeft_toLeftOfparentapp:layout_constraintTop_toTopOfparentLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationverticalandroid:gravitycenterandroid:layout_marginTop50dpandroid:layout_marginBottom10dpImageViewandroid:idid/imageView2android:layout_width120dpandroid:layout_height120dpapp:srcCompatdrawable/income_2 /TextViewandroid:idid/textView20android:layout_widthwrap_contentandroid:layout_heightmatch_parentandroid:layout_weight1android:text我的收支android:textColor#3F51B5android:textSize20spandroid:layout_marginTop10dp//LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_height100dpandroid:orientationhorizontalandroid:gravitycenter_verticalandroid:layout_marginHorizontal24dpandroid:layout_marginTop30dpLinearLayoutandroid:layout_widthwrap_contentandroid:layout_height100dpandroid:orientationverticalTextViewandroid:idid/textView33android:layout_widthwrap_contentandroid:layout_height50dpandroid:text日期 android:gravitycenter_verticalandroid:textColor#111113android:textSize18sp /TextViewandroid:idid/textView34android:layout_widthwrap_contentandroid:layout_height50dpandroid:text类型 android:gravitycenter_verticalandroid:textColor#FF111113android:textSize18sp //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_height100dpandroid:layout_weight1android:orientationverticalSpinnerandroid:idid/spin_dateandroid:layout_widthmatch_parentandroid:layout_height50dp /Spinnerandroid:idid/spin_typeandroid:layout_widthmatch_parentandroid:layout_height50dpandroid:layout_weight1 //LinearLayoutLinearLayoutandroid:layout_widthwrap_contentandroid:layout_height100dpandroid:orientationverticalandroid:gravitycenter_verticalButtonandroid:idid/btn_searchandroid:layout_width60dpandroid:layout_height40dpandroid:background#39DC54android:text搜索android:textColor#FAF9F9android:textSize12spapp:backgroundTint#5E97DA //LinearLayout/LinearLayoutImageViewandroid:layout_width360dpandroid:layout_height0.5dpandroid:background#D1CDCDandroid:layout_gravitycenterandroid:paddingHorizontal24dp/LinearLayoutandroid:layout_widthmatch_parentandroid:layout_height50dpandroid:gravitycenter_verticalandroid:orientationhorizontalandroid:layout_marginHorizontal24dpTextViewandroid:idid/textView32android:layout_widthwrap_contentandroid:layout_height50dpandroid:text总金额 android:gravitycenter_verticalandroid:textColor#FF111113android:textSize18sp /TextViewandroid:idid/tv_showandroid:layout_widthwrap_contentandroid:layout_height50dpandroid:layout_weight1android:textColor#4CAF65android:textSize24spandroid:gravitycenter_vertical/Buttonandroid:idid/btn_calcandroid:layout_width60dpandroid:layout_height40dpandroid:gravitycenter_verticalandroid:text计算android:textColor#FAF9F9android:textSize12spapp:backgroundTint#5E97DA //LinearLayoutImageViewandroid:layout_width360dpandroid:layout_height0.5dpandroid:background#D1CDCDandroid:layout_gravitycenterandroid:paddingHorizontal20dp/TextViewandroid:idid/textView31android:layout_widthmatch_parentandroid:layout_height40dpandroid:gravitycenter_verticalandroid:text查询结果 android:layout_marginTop20dpandroid:textColor#111113android:layout_marginHorizontal24dpandroid:textSize18sp/LinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationhorizontalandroid:layout_marginVertical20dpandroid:layout_marginHorizontal20dpTextViewandroid:idid/textView29android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:text序号android:textColor#6290c8android:textStyleboldandroid:textSize18spandroid:gravitycenter_horizontal/TextViewandroid:idid/textView26android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:text日期android:textColor#6290c8android:textStyleboldandroid:textSize18spandroid:gravitycenter_horizontal/TextViewandroid:idid/textView25android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:text类型android:textColor#6290c8android:textStyleboldandroid:textSize18spandroid:gravitycenter_horizontal/TextViewandroid:idid/textView27android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:text金额android:textColor#6290c8android:textStyleboldandroid:textSize18spandroid:gravitycenter_horizontal/TextViewandroid:idid/textView28android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:text说明android:textColor#6290c8android:textStyleboldandroid:textSize18spandroid:gravitycenter_horizontal//LinearLayoutListViewandroid:idid/searchlistviewandroid:layout_widthmatch_parentandroid:layout_height500dpandroid:layout_weight0android:layout_marginHorizontal20dp//LinearLayout/androidx.constraintlayout.widget.ConstraintLayout5收支管理页面activity_manage.xml 对于收支管理页面来说用户可以对自己的日常开销进行收支管理同时也可以进行添加、删除和修改等操作。具体代码如下 ?xml version1.0 encodingutf-8? androidx.constraintlayout.widget.ConstraintLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.ManageActivityLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:gravitycenter_horizontalandroid:orientationverticalapp:layout_constraintBottom_toBottomOfparentapp:layout_constraintLeft_toLeftOfparentapp:layout_constraintTop_toTopOfparentLinearLayoutandroid:layout_widthmatch_parentandroid:layout_height200dpandroid:gravitycenterandroid:orientationverticalImageViewandroid:idid/imageView2android:layout_width150dpandroid:layout_height150dpandroid:layout_marginTop20dpapp:srcCompatdrawable/income_1 /TextViewandroid:idid/textView20android:layout_widthwrap_contentandroid:layout_height30dpandroid:text收支管理android:textColor#3F51B5android:textSize20dp //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_height50dpandroid:gravitycenter_verticalandroid:orientationhorizontalTextViewandroid:idid/textView36android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginHorizontal20dpandroid:text您选择的序号是android:textColor#152029android:textSize18spandroid:textStylebold /TextViewandroid:idid/tv_testandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:hint暂未选择android:textColor#4CAF50android:textSize18sp //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginHorizontal20dpandroid:layout_marginVertical10dpandroid:gravitycenterandroid:orientationhorizontalTextViewandroid:idid/textView29android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_gravitycenterandroid:layout_weight1android:text序号android:textColor#111819android:textSize18sp /TextViewandroid:idid/textView26android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:text日期android:textColor#111819android:textSize18sp /TextViewandroid:idid/textView25android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:text类型android:textColor#111819android:textSize18sp /TextViewandroid:idid/textView27android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:text金额android:textColor#111819android:textSize18sp /TextViewandroid:idid/textView28android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:text说明android:textColor#111819android:textSize18sp //LinearLayoutImageViewandroid:layout_width380dpandroid:layout_height0.5dpandroid:background#D8D3D3android:paddingHorizontal20dp /ListViewandroid:idid/recordlistviewandroid:layout_widthwrap_contentandroid:layout_height120dpandroid:layout_weight1/ListViewLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginHorizontal14dpandroid:orientationhorizontalTextViewandroid:idid/textView18android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text日期: android:textColor#101112android:textSize18sp /EditTextandroid:idid/edt_dateandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:ems10android:hint填写日期如202107表示2021年7月android:inputTypetextPersonName //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginHorizontal14dpandroid:orientationhorizontalTextViewandroid:idid/textView21android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text类型: android:textColor#101112android:textSize18sp /EditTextandroid:idid/edt_typeandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:ems10android:hint类型为收入或支出android:inputTypetextPersonName //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginHorizontal14dpandroid:orientationhorizontalTextViewandroid:idid/textView30android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text金额: android:textColor#101112android:textSize18sp /EditTextandroid:idid/edt_moneyandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:ems10android:hint请输入金额android:inputTypetextPersonName //LinearLayoutLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:layout_marginHorizontal14dpandroid:orientationhorizontalTextViewandroid:idid/tv_stateandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:text说明: android:textColor#101112android:textSize18sp /EditTextandroid:idid/edt_stateandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_weight1android:ems10android:hint阐述说明android:inputTypetextPersonName //LinearLayoutLinearLayoutandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginVertical30dpButtonandroid:idid/btn_addandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginHorizontal10dpandroid:layout_weight1android:text添加app:backgroundTint#78C6A3 /Buttonandroid:idid/btn_updateandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginHorizontal10dpandroid:layout_weight1android:text修改app:backgroundTint#56AB91 /Buttonandroid:idid/btn_deleteandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_marginHorizontal10dpandroid:layout_weight1android:text删除app:backgroundTint#358F80 //LinearLayout/LinearLayout /androidx.constraintlayout.widget.ConstraintLayout6列表数据记录record_item_layout.xml record_item_layout.xml 主要用途是存储列表的传输数据。具体代码如下 ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationhorizontalandroid:layout_marginHorizontal20dpandroid:gravitycenter_horizontalandroid:paddingVertical2dpTextViewandroid:idid/list_idandroid:layout_width40dpandroid:layout_height24dpandroid:layout_weight1android:textSize18spandroid:gravitycenter_horizontal /TextViewandroid:idid/list_dateandroid:layout_width90dpandroid:layout_height24dpandroid:layout_weight1android:textSize18spandroid:gravitycenter_horizontal /TextViewandroid:idid/list_typeandroid:layout_width70dpandroid:layout_height24dpandroid:layout_weight1android:textSize18spandroid:gravitycenter_horizontal /TextViewandroid:idid/list_moneyandroid:layout_width70dpandroid:layout_height24dpandroid:layout_weight1android:textSize18spandroid:gravitycenter_horizontal /TextViewandroid:idid/list_stateandroid:layout_width90dpandroid:layout_height24dpandroid:layout_weight1android:textSize18spandroid:gravitycenter_horizontal //LinearLayout /LinearLayout 3. 逻辑结构 写完静态页面之后接下来我们要对每个页面的逻辑进行编写。现在我们来看一下各个 Activity 类所实现的内容都有些什么呢 1DBHelper类 DBHelper 类用于创建数据库表和数据库数据同时实现与数据库操作相关的登录和注册方法。具体代码实现如下 package com.financial.management;import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper;public class DBHelper extends SQLiteOpenHelper {public static final String DB_NAME Test.db;public static final String TABLE_NAME userinfo;public static final String COLUMN_USERID uid;public static final String COLUMN_USERPWD upwd;//创建数据库语句private static final String CREATE_TABLE create table if not exists TABLE_NAME ( COLUMN_USERID text not null primary key, COLUMN_USERPWD text not null);public DBHelper(Context context) {super(context, DB_NAME, null, 1);}//创建数据库方法Overridepublic void onCreate(SQLiteDatabase db) {try {db.execSQL(CREATE_TABLE);db.execSQL(insert into TABLE_NAME values(11,11));} catch (SQLException e) {e.printStackTrace();}}//重置数据库方法(先删表再建表)Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {db.execSQL(drop table if exists TABLE_NAME);db.execSQL(CREATE_TABLE);}//登录方法public User userlogin(String userId, String userPwd) {User user null;SQLiteDatabase db getReadableDatabase();Cursor cursor db.query(TABLE_NAME,new String[]{COLUMN_USERID, COLUMN_USERPWD},COLUMN_USERID ? and COLUMN_USERPWD ?,new String[]{userId, userPwd},null,null,null);if (cursor.getCount() 0) {cursor.moveToFirst();user new User();user.setUserId(cursor.getString(cursor.getColumnIndex(COLUMN_USERID)));user.setUserPwd(cursor.getString(cursor.getColumnIndex(COLUMN_USERPWD)));}return user;}//注册方法public long registerUser(User user) {SQLiteDatabase db getWritableDatabase();ContentValues contentValues new ContentValues();contentValues.put(COLUMN_USERID, user.getUserId());contentValues.put(COLUMN_USERPWD, user.getUserPwd());return db.insert(TABLE_NAME, null, contentValues);} }2MainActivity类 MainActivity 类是用户登录页面的Activity主要编写用户登录页面的代码逻辑。具体代码实现如下 package com.financial.management;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;import java.util.ArrayList;//登录页面逻辑 public class MainActivity extends AppCompatActivity {EditText edt_id,edt_pwd;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);edt_id findViewById(R.id.edt_uid);edt_pwd findViewById(R.id.edt_upwd);Button btn_login findViewById(R.id.btn_login);//登录按键btn_login.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {try {String userIdedt_id.getText().toString();String userPwdedt_pwd.getText().toString();DBHelper dbuserHelpernew DBHelper(getApplicationContext());User user dbuserHelper.userlogin(userId,userPwd);//登录成功跳转对应类型界面if(user!null) {Toast.makeText(getApplicationContext(), user.getUserId() 登录成功, Toast.LENGTH_SHORT).show();Intent intent;ArrayListUser list new ArrayList();list.add(user);intent new Intent(getApplicationContext(), UserCenterActivity.class);intent.putParcelableArrayListExtra(LoginUser, list);startActivity(intent);}else{Toast.makeText(getApplicationContext(),登录失败密码错误或账号不存在,Toast.LENGTH_SHORT).show();}} catch (Exception e) {e.printStackTrace();Toast.makeText(getApplicationContext(),数据库异常,Toast.LENGTH_SHORT).show();}}});//注册按键Button btn_registerfindViewById(R.id.btn_register);btn_register.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {Intent intentnew Intent(getApplicationContext(),RegisterActivity.class);startActivity(intent);}});} }3RegisterActivity类 RegisterActivity 类是用户注册页面的Activity主要编写用户注册页面的业务逻辑。具体代码实现如下 package com.financial.management;import androidx.appcompat.app.AppCompatActivity;import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast;import java.util.ArrayList;//注册页面逻辑 public class RegisterActivity extends AppCompatActivity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_register);final EditText edt_rid findViewById(R.id.edt_rid);final EditText edt_rpwd findViewById(R.id.edt_rpwd);//注册按键Button btn_registerffindViewById(R.id.btn_registeruser);btn_registerf.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {User user new User();user.setUserId(edt_rid.getText().toString());user.setUserPwd(edt_rpwd.getText().toString());DBHelper dbUserHelper new DBHelper(getApplicationContext());if (dbUserHelper.registerUser(user) 0) {Toast.makeText(getApplicationContext(), 注册成功, Toast.LENGTH_SHORT).show();Intent intent;ArrayListUser list new ArrayList();list.add(user);intent new Intent(getApplicationContext(), MainActivity.class);startActivity(intent);}else{Toast.makeText(getApplicationContext(), 您已经注册过此账户请返回登录, Toast.LENGTH_SHORT).show();}}});} }4UserCenterActivity类 UserCenterActivity 类是个人中心页面的Activity主要编写个人中心各种按钮跳转的业务逻辑。具体代码实现如下 package com.financial.management;import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity;import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import android.widget.TextView;import java.util.ArrayList;//用户个人中心页面逻辑 public class UserCenterActivity extends AppCompatActivity {ArrayListUser list;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_user_center);Intent intentgetIntent();list intent.getParcelableArrayListExtra(LoginUser);User userlist.get(0);final String usernameuser.getUserId();TextView tv_welcomefindViewById(R.id.tv_welcome);tv_welcome.setText(欢迎您 ,用户username);//收支管理ImageView btn_recordmanage findViewById(R.id.btn_recordmanage);btn_recordmanage.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {Intent intent1new Intent(getApplicationContext(), ManageActivity.class);startActivity(intent1);}});//收支查询ImageView btn_searchrecordfindViewById(R.id.btn_searchrecord);btn_searchrecord.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {Intent intent2new Intent(getApplicationContext(),SearchRecordActivity.class);startActivity(intent2);}});//收支统计ImageView btn_calcmoneyfindViewById(R.id.btn_calcmoney);btn_calcmoney.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {Intent intent3new Intent(getApplicationContext(),SearchRecordActivity.class);startActivity(intent3);}});//退出按键ImageView btn_exitfindViewById(R.id.btn_exit);btn_exit.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {AlertDialog dialog new AlertDialog.Builder(UserCenterActivity.this).setTitle(退出操作).setMessage(确定退出不继续玩玩).setPositiveButton(确定, new DialogInterface.OnClickListener() {Overridepublic void onClick(DialogInterface dialog, int which) {Intent intentnew Intent(getApplicationContext(), MainActivity.class);startActivity(intent);}}).setNegativeButton(继续留下, new DialogInterface.OnClickListener() {Overridepublic void onClick(DialogInterface dialog, int which) {}}).create();dialog.show();}});} }5SearchRecordActivity类 SearchRecordActivity 类是搜索记录页面的Activity主要编写我的收支页面的业务逻辑。具体代码实现如下 package com.financial.management;import androidx.appcompat.app.AppCompatActivity;import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast;import java.util.ArrayList; import java.util.HashMap; import java.util.Map;//收支记录页面业务逻辑 public class SearchRecordActivity extends AppCompatActivity {//定义spinner中的数据private String[] date_data {, 202101, 202102, 202103, 202104, 202105,202106,202107,202108,202109,202110,202111,202112};private String[] type_data {, 收入, 支出};Spinner spin_date, spin_type;ListView listView;TextView tv_show;float sum0;//数据库private String selectDate, selectType;private static final String DATABASE_NAME Test.db;private static final String TABLE_NAME record;private static final String COLUMN_ID id;private static final String COLUMN_DATE date;private static final String COLUMN_TYPE type;private static final String COLUMN_MONEY money;private static final String COLUMN_STATE state;private SQLiteDatabase sqLiteDatabase null;private void selectSumMoney() {//自定义查询的sql语句String sql;//如果查询时间和查询类型都为空则查询整个表if (TextUtils.isEmpty(selectDate) TextUtils.isEmpty(selectType)) {sql select * from TABLE_NAME;//如果有查询时间没有查询类型查询指定内容} else if (!TextUtils.isEmpty(selectDate) TextUtils.isEmpty(selectType)) {sql select * from TABLE_NAME where date selectDate ;//如果没有查询时间有查询类型查询指定内容} else if (TextUtils.isEmpty(selectDate) !TextUtils.isEmpty(selectType)) {//如果没有查询时间有查询类型sql select * from TABLE_NAME where type selectType;} else {//否则查询条件都不为空查询指定内容sql select * from TABLE_NAME where date selectDate and type selectType;}Cursor cursor sqLiteDatabase.rawQuery(sql, null);while (cursor.moveToNext()) {float money cursor.getFloat(cursor.getColumnIndex(COLUMN_MONEY));sumsummoney;//list.add(map);}String money2String.valueOf(sum);tv_show.setText(money2);sum0;}//选择数据private void selectData() {//自定义查询的sql语句String sql;//如果查询时间和查询类型都为空则查询整个表if (TextUtils.isEmpty(selectDate) TextUtils.isEmpty(selectType)) {sql select * from TABLE_NAME;//如果有查询时间没有查询类型查询指定内容} else if (!TextUtils.isEmpty(selectDate) TextUtils.isEmpty(selectType)) {sql select * from TABLE_NAME where date selectDate ;//如果没有查询时间有查询类型查询指定内容} else if (TextUtils.isEmpty(selectDate) !TextUtils.isEmpty(selectType)) {//如果没有查询时间有查询类型sql select * from TABLE_NAME where type selectType;} else {//否则查询条件都不为空查询指定内容sql select * from TABLE_NAME where date selectDate and type selectType;}//将查询到的数据封装到CursorCursor cursor sqLiteDatabase.rawQuery(sql, null);ArrayListMapString, String list new ArrayListMapString, String();if (cursor.getCount() 0) {//查无数据则怒不显示列表// listView.setVisibility(View.GONE);Toast.makeText(getApplicationContext(), 无数据, Toast.LENGTH_SHORT).show();} else {//查有数据则显示列表listView.setVisibility(View.VISIBLE);while (cursor.moveToNext()) {int id cursor.getInt(cursor.getColumnIndex(COLUMN_ID));String date cursor.getString(cursor.getColumnIndex(COLUMN_DATE));String type cursor.getString(cursor.getColumnIndex(COLUMN_TYPE));float money cursor.getFloat(cursor.getColumnIndex(COLUMN_MONEY));String state cursor.getString(cursor.getColumnIndex(COLUMN_STATE));MapString, String map new HashMapString, String();map.put(id, String.valueOf(id));map.put(date, date);map.put(type, type);map.put(money, String.valueOf(money));map.put(state, state);list.add(map);}//创建SimpleAdapterSimpleAdapter simpleAdapter new SimpleAdapter(getApplicationContext(),list,R.layout.record_item_layout,new String[]{id, date, type, money, state},new int[]{R.id.list_id, R.id.list_date, R.id.list_type, R.id.list_money, R.id.list_state});listView.setAdapter(simpleAdapter);}}//时间和类别spinner点击事件private void initClick() {//时间事件spin_date.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {Overridepublic void onItemSelected(AdapterView? parent, View view, int position, long id) {selectDate date_data[position];}Overridepublic void onNothingSelected(AdapterView? parent) {}});//类别事件spin_type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {Overridepublic void onItemSelected(AdapterView? parent, View view, int position, long id) {selectType type_data[position];}Overridepublic void onNothingSelected(AdapterView? parent) {}});findViewById(R.id.btn_search).setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {selectData();}});}Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_search_record);tv_showfindViewById(R.id.tv_show);try {//打开数据库如果是第一次会创建该数据库模式为MODE_PRIVATEsqLiteDatabase openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);//执行创建表的sql语句虽然每次都调用但只有首次才创建表//执行查询listView findViewById(R.id.searchlistview);//绑定列表selectData();} catch (SQLException e) {Toast.makeText(this, 数据库异常!, Toast.LENGTH_LONG).show();e.printStackTrace();}ArrayAdapterString adapter newArrayAdapterString(this, android.R.layout.simple_spinner_item, date_data);adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);spin_date findViewById(R.id.spin_date);spin_date.setAdapter(adapter);ArrayAdapterString adapter1 newArrayAdapterString(this, android.R.layout.simple_spinner_item, type_data);adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);spin_type findViewById(R.id.spin_type);spin_type.setAdapter(adapter1);initClick();Button btn_calcfindViewById(R.id.btn_calc);btn_calc.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {selectSumMoney();}});} }6ManageActivity类 ManageActivity 类是收支管理页面的Activity主要编写用户的收入和支出的业务逻辑实现收支的增删改查。具体代码实现如下 package com.financial.management;import androidx.appcompat.app.AppCompatActivity; import android.content.DialogInterface; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast;import androidx.appcompat.app.AlertDialog; import java.util.ArrayList; import java.util.HashMap; import java.util.Map;public class ManageActivity extends AppCompatActivity {private SQLiteDatabase sqLiteDatabase null;private int selectId -1;EditText edt_date, edt_type, edt_money, edt_state;TextView tv_test;private static final String DATABASE_NAME Test.db;private static final String TABLE_NAME record;private static final String COLUMN_ID id;private static final String COLUMN_DATE date;private static final String COLUMN_TYPE type;private static final String COLUMN_MONEY money;private static final String COLUMN_STATE state;//创建表private static final String CREATE_TABLE create table if not exists TABLE_NAME ( COLUMN_ID integer primary key autoincrement, COLUMN_DATE text, COLUMN_TYPE text, COLUMN_MONEY float, COLUMN_STATE text);//自定义的查询方法private void selectData() {//遍历整个表String sql select * from TABLE_NAME ;//把查询数据封装到CursorCursor cursor sqLiteDatabase.rawQuery(sql, null);ArrayListMapString, String list new ArrayListMapString, String();//用while循环遍历Cursor再把它分别放到map中最后统一存入list中便于调用while (cursor.moveToNext()) {int id cursor.getInt(cursor.getColumnIndex(COLUMN_ID));String date cursor.getString(cursor.getColumnIndex(COLUMN_DATE));String type cursor.getString(cursor.getColumnIndex(COLUMN_TYPE));float money cursor.getFloat(cursor.getColumnIndex(COLUMN_MONEY));String state cursor.getString(cursor.getColumnIndex(COLUMN_STATE));MapString, String map new HashMapString, String();map.put(id, String.valueOf(id));map.put(date, date);map.put(type, type);map.put(money, String.valueOf(money));map.put(state, state);list.add(map);}//创建SimpleAdapterSimpleAdapter simpleAdapter new SimpleAdapter(getApplicationContext(),list,R.layout.record_item_layout,new String[]{id, date, type, money, state},new int[]{R.id.list_id, R.id.list_date, R.id.list_type, R.id.list_money, R.id.list_state});final ListView listView findViewById(R.id.recordlistview);//绑定适配器listView.setAdapter(simpleAdapter);//设置ListView单击事件listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {Overridepublic void onItemClick(AdapterView? parent, View view, int position, long id) {ListView tempList (ListView) parent;View mView tempList.getChildAt(position);TextView list_id mView.findViewById(R.id.list_id);TextView list_date mView.findViewById(R.id.list_date);TextView list_type mView.findViewById(R.id.list_type);TextView list_money mView.findViewById(R.id.list_money);TextView list_state mView.findViewById(R.id.list_state);String rid list_id.getText().toString();String date list_date.getText().toString();String type list_type.getText().toString();String money list_money.getText().toString();String state list_state.getText().toString();tv_test.setText(rid);edt_date.setText(date);edt_type.setText(type);edt_money.setText(money);edt_state.setText(state);selectId Integer.parseInt(rid);}});}Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_manage);try {sqLiteDatabase openOrCreateDatabase(DATABASE_NAME, MODE_PRIVATE, null);sqLiteDatabase.execSQL(CREATE_TABLE);//执行查询selectData();} catch (SQLException e) {Toast.makeText(this, 数据库异常!, Toast.LENGTH_LONG).show();e.printStackTrace();}tv_test findViewById(R.id.tv_test);edt_date findViewById(R.id.edt_date);edt_type findViewById(R.id.edt_type);edt_money findViewById(R.id.edt_money);edt_state findViewById(R.id.edt_state);//新增按键Button btn_add findViewById(R.id.btn_add);btn_add.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {if (edt_date.getText().toString().equals() | edt_type.getText().toString().equals() | edt_money.getText().toString().equals() | edt_state.getText().toString().equals()) {Toast.makeText(ManageActivity.this, 数据不能为空!, Toast.LENGTH_LONG).show();return;}String date edt_date.getText().toString();String type edt_type.getText().toString();String money edt_money.getText().toString();String state edt_state.getText().toString();//定义添加数据的sql语句String sql insert into TABLE_NAME ( COLUMN_DATE , COLUMN_TYPE , COLUMN_MONEY , COLUMN_STATE ) values( date , type , money , state );//执行sql语句sqLiteDatabase.execSQL(sql);Toast.makeText(getApplicationContext(), 新增数据成功!, Toast.LENGTH_LONG).show();//刷新显示列表selectData();//消除数据tv_test.setText();edt_date.setText();edt_type.setText();edt_money.setText();edt_state.setText();}});//修改按键Button btn_update findViewById(R.id.btn_update);btn_update.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {//无选择提示if (selectId -1) {Toast.makeText(getApplicationContext(), 请选择要修改的行!, Toast.LENGTH_LONG).show();return;}//判断是否有空数据if (edt_date.getText().toString().equals() | edt_type.getText().toString().equals() | edt_money.getText().toString().equals() | edt_state.getText().toString().equals()) {Toast.makeText(getApplicationContext(), 数据不能为空!, Toast.LENGTH_LONG).show();return;}String date edt_date.getText().toString();String type edt_type.getText().toString();String money edt_money.getText().toString();String state edt_state.getText().toString();//定义修改数据的sql语句String sql update TABLE_NAME set COLUMN_DATE date ,type type ,money money ,state state where id selectId;//执行sql语句sqLiteDatabase.execSQL(sql);Toast.makeText(getApplicationContext(), 修改数据成功!, Toast.LENGTH_LONG).show();//刷新显示列表selectData();selectId -1;//消除数据tv_test.setText();edt_date.setText();edt_type.setText();edt_money.setText();edt_state.setText();}});//删除按键Button btn_delete findViewById(R.id.btn_delete);btn_delete.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View v) {//无选择提示if (selectId -1) {Toast.makeText(ManageActivity.this, 请选择要删除的行!, Toast.LENGTH_LONG).show();return;}//定义删除对话框AlertDialog dialog new AlertDialog.Builder(ManageActivity.this).setTitle(删除操作).setMessage(确定删除此操作不可逆请慎重选择).setPositiveButton(确定, new DialogInterface.OnClickListener() {Overridepublic void onClick(DialogInterface dialog, int which) {//定义删除的sql语句String sql delete from TABLE_NAME where id selectId;//执行sql语句sqLiteDatabase.execSQL(sql);//刷新显示列表Toast.makeText(getApplicationContext(), 删除数据成功!, Toast.LENGTH_LONG).show();selectData();selectId -1;//清除数据tv_test.setText();edt_date.setText();edt_type.setText();edt_money.setText();edt_state.setText();}}).setNegativeButton(取消, new DialogInterface.OnClickListener() {Overridepublic void onClick(DialogInterface dialog, int which) {}}).create();dialog.show();}});} }7User类 User 类是用户类Activity用于获取用户ID以及密码。具体代码实现如下 package com.financial.management; import android.os.Parcel; import android.os.Parcelable;public class User implements Parcelable {private String userId;private String userPwd;public String getUserId() {return userId;}public void setUserId(String userId) {this.userId userId;}public String getUserPwd() {return userPwd;}public void setUserPwd(String userPwd) {this.userPwd userPwd;}Overridepublic int describeContents() {return 0;}Overridepublic void writeToParcel(Parcel dest, int flags) {dest.writeString(this.userId);dest.writeString(this.userPwd);}public User() {}protected User(Parcel in) {this.userId in.readString();this.userPwd in.readString();}public static final CreatorUser CREATOR new CreatorUser() {Overridepublic User createFromParcel(Parcel source) {return new User(source);}Overridepublic User[] newArray(int size) {return new User[size];}}; }三、运行结果Result 到这里整个系统的设计就差不多要结束啦现在我们用一段视频来演示整个系统的运行效果 四、结束语 在拿到这个课题呢周一首先对课题进行了系统结构设计结构设计完成之后就到了编码阶段。编码阶段分为两部分进行先是进行静态页面的楷模而后到了业务逻辑的编写。 讲到这里整个系统从设计阶段到编码阶段的整个过程讲解就结束啦这也算是我学习Android的第一个小作品作品不完美之处较多后续还将会继续改进~ 本文代码已上传至github戳此链接可下载代码~ 彩蛋 One More Thing (:不合理设计 年月份数据写的太固定了没有可扩展性日期应该用日期选择器来做而不应该是以文本的形式收入和支出应该以单选框来进行选择而不应该是文本的形式…… (:番外篇 关注公众号星期一研究室第一时间关注学习干货更多精选专栏待你解锁~如果这篇文章对你有用记得留个脚印jio再走哦~以上就是本文的全部内容我们下期见
http://wiki.neutronadmin.com/news/246901/

相关文章:

  • 想找做海报的超清图片去哪个网站找南宁网站建设公司业绩
  • 关于做一动物网站的界面个企业网站做电脑营销
  • 摄影网站设计与制作企业网站一定要备案吗
  • 旅游网站建设成都免费发布广告的平台
  • 兰溪市建设局网站wordpress视频站代码
  • 基于5G的网站设计让别人看到自己做的网站
  • 如何制作网站机器人网站的seo
  • 建立网站需要多少钱费用二维码生成器哪个软件好
  • 网站建设业务前景投资公司网站模板
  • wordpress多域名绑定资阳优化团队资讯
  • 做网站的是干嘛的2024年营业执照年审入口
  • 达州做淘宝网站网站挣钱网
  • 凡科网站建设之后怎么删除南通营销平台网站建设
  • 设计公司网站价格外贸客户搜索软件
  • seo网站内部优化方案酒仙网技术开发与网站建设方面
  • 网站营销力家政公司电话
  • 网站 wordpress深圳做网站建设的公司
  • 上海定制网站建设如何做网站推广在找产品营销推广吗
  • 智联招聘网站怎么做微招聘信息东莞国药官网网上商城
  • 有哪些网站是可以做免费推广的页面布局标准格式
  • 有谁想做网站 优帮云做宠物商品的网站
  • 建设网站需要备案么小程序模板消息推送
  • 易语言跳到指定网站怎么做江西建设单位网站
  • 中英文网站开发费用最后的目的是什么
  • 网站生成静态重庆制片公司
  • 免费行情网站app下载大全层流病房建设单位网站
  • 网站排名优化外包微博个人网页设计模板
  • 微信商城和微网站建站哪家好 discuz
  • 广东网站备案进度查询成全视频在线看
  • 福田网站制作比较好的在网站图片源代码alt写入关键词后为什么不显示只显示title内容