android软件简约记账app开发day06-将记账条目添加到数据库并且绘制备注页面
android软件简约记账app开发day06-将记账条目添加到数据库并且绘制备注页面
首先写添加到数据库
在DBOpenHelper中添加创建记账表的语句
//创建记账表
sql = "create table accounttb(id integer primary key autoincrement,typename varchar(10),sImageId integer,beizhu varchar(80),money float," +
"time varchar(60),year integer,month integer,day integer,kind integer)";
db.execSQL(sql);
在数据库管理类中添加保存方法
/*
* 向记账表当中插入一条元素
* */
public static void insertItemToAccounttb(AccountBean bean){
ContentValues values = new ContentValues();
values.put("typename",bean.getTypename());
values.put("sImageId",bean.getsImageId());
values.put("beizhu",bean.getBeizhu());
values.put("money",bean.getMoney());
values.put("time",bean.getTime());
values.put("year",bean.getYear());
values.put("month",bean.getMonth());
values.put("day",bean.getDay());
values.put("kind",bean.getKind());
db.insert("accounttb",null,values);
}
我们在baseFragment类中写一个保存到数据库的方法,为了方便继承实现,定义成抽象方法,并且把该类改为抽象类。
/**
* 将数据保存到数据库,因为收入支出保存不同,所以我们封装成抽象类,抽象方法。
*/
public abstract void saveAccountToDB();
分别在子类中重写
@Override
public void saveAccountToDB() {
accountBean.setKind(1);
DBManager.insertItemToAccounttb(accountBean);
}
@Override
public void saveAccountToDB() {
accountBean.setKind(0);
DBManager.insertItemToAccounttb(accountBean);
}
绘制备注界面
我们在点击备注时,要弹出界面,我们今天只画一下该界面
新建dialog_beizhu.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:padding="10dp"
android:background="@color/white">
<TextView
android:id="@+id/dialog_beizhu_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_remark"
android:textSize="16sp"
android:textColor="@color/black"/>
<EditText
android:id="@+id/dialog_beizhu_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/dialog_beizhu_tv"
android:hint="@string/remark"
android:layout_marginTop="10dp"
android:layout_marginBottom="20dp"
android:textSize="14sp"
android:background="@color/white">
<requestFocus/>
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/dialog_beizhu_et"
android:padding="10dp">
<Button
android:id="@+id/dialog_beizhu_btn_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/cancel"
android:background="@drawable/dialog_btn_bg"
android:textStyle="bold"
android:textColor="@color/green_006400"
android:layout_marginRight="5dp"/>
<Button
android:id="@+id/dialog_beizhu_btn_ensure"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ensure"
android:background="@drawable/main_recordbtn_bg"
android:textStyle="bold"
android:textColor="@color/white"
android:layout_marginRight="5dp"/>
</LinearLayout>
</RelativeLayout>
在drawable中添加drawable文件
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 四个角设定弧度-->
<corners android:radius="20dp"/>
<!-- 填充颜色-->
<solid android:color="@color/white"/>
<stroke android:color="@color/green_006400" android:width="3dp"/>
</shape>
在strings.xml中添加变量
<string name="add_remark">添加备注</string>
<string name="remark">备注</string>
<string name="ensure">确定</string>
<string name="cancel">取消</string>
效果图:

今天的内容比较简单,我们明天见。
android软件简约记账app开发day06-将记账条目添加到数据库并且绘制备注页面的更多相关文章
- android软件简约记账app开发day05-记账页面条目代码优化和bug解决
android软件简约记账app开发day05-记账页面条目代码优化和bug解决 今天还是因为该bug又极大的耽误了项目进程,该开发文档都要没有时间来写了. 先说bug吧,在昨天已经实现了页面图标的展 ...
- android软件简约记账app开发day10-主页面模块--头信息的展示,和之后功能完善的目标。
android软件简约记账app开发day10-主页面模块--头信息的展示,和之后功能完善的目标. 今天来写主界面头信息的展示,也就是将第一天的写的layout中的item_main_top展示到主界 ...
- android软件简约记账app开发day09-主页面模块,收支记账信息的展示
android软件简约记账app开发day09-主页面模块,收支记账信息的展示 我们第一天已经绘制了记账条目的界面,也在主界面设置了LietView来展示记账条目,今天来实现记账后再主界面的展示效果 ...
- android软件简约记账app开发day08-时间对话框的书写+改bug,改bug
android软件简约记账app开发day08-时间对话框的书写+改bug,改bug 绘制对话跨页面 在添加记账信息功能中,我提供了用户添加备注添加事件的功能,设计是点击时间会弹出一个时间对话框供用户 ...
- android软件简约记账app开发day07-备注界面完善
android软件简约记账app开发day07-备注界面完善 ## 昨天我们已经绘制了备注页面,今天来用Java代码组装完善一下. 首先我们新建BeiZhuDialog类关联备注页面,并且实现点击接口 ...
- android软件简约记账app开发day04-记账页面条目的代码书写
android软件简约记账app开发day04-记账页面条目的代码书写 在前三天我们完成了基本的界面展示,从今天开始,我们进入到后台逻辑代码的编写中,今天开发记账条目的代码 我们在主页面点击记一笔图标 ...
- android软件简约记账app开发day03-自定义键盘的书写
android软件简约记账app开发day03-自定义键盘的书写 我们在fragment界面使用了自定义的keybroad键盘,所以今天我们来书写自定义的键盘代码 新建util包,新建keyboard ...
- android软件简约记账app开发day02-收入支出明细页面绘制
android软件简约记账app开发day02-收入支出明细页面绘制 效果图 列表界面绘制 新建layout文件-item_mainlv.xml大体使用绝对布局,嵌套相对布局,嵌套文本内容实现 < ...
- android软件简约记账app开发day01-今日收支明细的界面绘制
android软件简约记账app开发day01-今日收支明细的界面绘制 导入素材 导入在阿里iconfront图标库下载的字体图标分为大小两种,分别导入到项目目录mipmap-hdpi和mipmap- ...
随机推荐
- KVM 虚拟化基本知识,virtio工作原理
KVM虚拟化的基本知识,virtio的工作流程及原理,virtio-vhost, virtio-vhost-user pci 配置空间,是谁在kick 写pci配置空间的?又是通过什么机制通知给qem ...
- ES6-ES12部分简单知识点总结,希望对大家有用~
ES6-ES12简单知识点总结 1.ES6相关知识点 1.1.对象字面量的增强 ES6中对对象字面量的写法进行了增强,主要包含以下三个方面的增强: 属性的简写:当给对象设置属性时,如果希望变量名和属性 ...
- 不会DRF?源码都分析透了确定不来看?
目录 不会DRF?源码都分析透了确定不来看? 快速使用DRF写出接口 序列化和反序列化 drf快速使用 views.py serializer.py urls.py 在settings的app中注册 ...
- 使用 Spring 有哪些方式?
使用 Spring 有以下方式: 作为一个成熟的 Spring Web 应用程序. 作为第三方 Web 框架,使用 Spring Frameworks 中间层. 用于远程使用. 作为企业级 Java ...
- 学习zabbix(七)
zabbix自定义监控项 1.创建主机组,可以根据redis.mysql.web等创建对于的主机组 2.创建主机 3.创建Screens 4.自定义监控项 zabbix_agentd.conf配置文件 ...
- Python - time标准库使用与程序计时
- STM32 之 HAL库(固件库)
1 STM32的三种开发方式 通常新手在入门STM32的时候,首先都要先选择一种要用的开发方式,不同的开发方式会导致你编程的架构是完全不一样的.一般大多数都会选用标准库和HAL库,而极少部分人会通过直 ...
- gulp详细基础教程
一.gulp简介 1.gulp是什么? gulp是前端开发过程中一种基于流的代码构建工具,是自动化项目的构建利器:它不仅能对网站资源进行优化,而且在开发过程中很多重复的任务能够使用正确的工具自动完成: ...
- 微信小程序黑客马拉松即将开始,来做最酷的 Mini Program Creators!
微信小程序黑客马拉松正式启动 近日,小程序斩获一项世界级殊荣--作为一项全新的技术和应用创新,小程序首次获选世界互联网领先科技成果.目前小程序应用数量已超过 100 万,覆盖了 200 多个细分行业, ...
- SQL之总结(二)
4.关于取两个日期之间的年份: ceil(MONTHS_BETWEEN(sysdate, c.sendtime)/12) workTime ceil(n) 取大于等于n的最小整数 floor(n) 取 ...