【Android】家庭记账本手机版开发报告一
一、说在前面
昨天 | 学习了数据库的一些简单操作 |
今天 | 使用数据库,完成对记账本的账单记录的增删 |
问题 | 没有 |
二、数据库
1、账单表的结构
(注 id:账单的唯一标识,uid:记录账单的用户的id,cost_time:记录账单的时间,cost_type:账单类型,cost_money:账单金额。)
2、Entity:AccountRecord.java
package com.me.familybookkeepingbook; import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey; @Entity
public class AccountRecord {
@PrimaryKey(autoGenerate = true)
private int id;
@ColumnInfo(name = "uid")
private int uid;
@ColumnInfo(name = "cost_time")
private String costTime;
@ColumnInfo(name = "cost_type")
private String costType;
@ColumnInfo(name = "cost_money")
private Double costMoney; public AccountRecord(int uid, String costTime, String costType, Double costMoney) {
this.uid = uid;
this.costTime = costTime;
this.costType = costType;
this.costMoney = costMoney;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public int getUid() {
return uid;
} public void setUid(int uid) {
this.uid = uid;
} public String getCostTime() {
return costTime;
} public void setCostTime(String costTime) {
this.costTime = costTime;
} public String getCostType() {
return costType;
} public void setCostType(String costType) {
this.costType = costType;
} public Double getCostMoney() {
return costMoney;
} public void setCostMoney(Double costMoney) {
this.costMoney = costMoney;
}
}
3、对数据库的操作:AccountRecordDao.java
package com.me.familybookkeepingbook; import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update; import java.util.List; @Dao
public interface AccountRecordDao {
@Insert
void insertAccountRecord (AccountRecord ... AccountRecords);
@Update
void updateAccountRecord (AccountRecord ... AccountRecords);
@Delete
void deleteAccountRecord (AccountRecord ... AccountRecords);
@Query("DELETE From ACCOUNTRECORD")
void deleteAllAccountRecord ();
@Query("SELECT * From ACCOUNTRECORD ORDER BY ID DESC")
List<AccountRecord> getAllAccountRecord ();
}
AccountRecordDatabase.java
package com.me.familybookkeepingbook; import androidx.room.Database;
import androidx.room.RoomDatabase;
@Database(entities = {AccountRecord.class },version = 1,exportSchema = false)
public abstract class AccountRecordDatabase extends RoomDatabase {
public abstract AccountRecordDao getAccountRecordDao();
}
三、界面布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"> <androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.8" /> <ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginLeft="1dp"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> <TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/textview"
android:textSize="24sp" />
</ScrollView> <Button
android:id="@+id/buttonInsert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buttonInsert"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/buttonDelete"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline" /> <Button
android:id="@+id/buttonDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buttonDalete"
app:layout_constraintBottom_toBottomOf="@+id/buttonInsert"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/buttonInsert"
app:layout_constraintTop_toTopOf="@+id/buttonInsert" />
</androidx.constraintlayout.widget.ConstraintLayout>
四、界面和数据的绑定
1、界面的更新
void updateView(){
List<AccountRecord> list = accountRecordDao.getAllAccountRecord();
String text = "";
for (int i=0;i<list.size();i++){
AccountRecord accountRecord = list.get(i);
text += accountRecord.getId() + " " + accountRecord.getCostType() + " "+accountRecord.getCostTime() +" "+
accountRecord.getCostMoney() +"\n";
}
textView.setText(text);
}
2、按键的监听
buttonInsert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AccountRecord accountRecord = new AccountRecord(1,"2020-01-26","学习",100.0);
accountRecordDao.insertAccountRecord(accountRecord);
updateView();
}
});
buttonDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
accountRecordDao.deleteAllAccountRecord();
updateView();
}
});
五、运行测试
1、插入:
2、删除
【Android】家庭记账本手机版开发报告一的更多相关文章
- 【Android】家庭记账本手机版开发报告五
一.说在前面 昨天 1.添加菜单(查询.清除所有等)2.使用滑动删除 今天 1.创建登入和注册界面 2.向数据库添加一张用户表 问题 做完后在登入时有bug(未解决) 二.界面的搭建 1 ...
- 【Android】家庭记账本手机版开发报告二
一.说在前面 昨天 完成了对记账本的账单的增删 今天 完善昨天的框架结构( 1.引入ViewModel管理数据.使MainActive 只管理界面.不再管数据了 2.引入AsyncTask.后台执行. ...
- 【Android】家庭记账本手机版开发报告七
一.说在前面 昨天 实现了账单的图标显示 今天 本地化,测试APP,将工程源码放到github上 源码:https://github.com/xiaotian12-call/Android_Boo ...
- 【Android】家庭记账本手机版开发报告六
一.说在前面 昨天 1.创建登入和注册界面:2.向数据库添加一张用户表 今天 用图标显示账单情况 问题 1.使用第三方库 hellochart,时添加依赖构建失败 2.在 chertFragmen ...
- 【Android】家庭记账本手机版开发报告四
一.说在前面 昨天 对界面显示和逻辑结构进行完善 今天 1.添加菜单(查询.清除所有等) 2.使用滑动删除 问题 1.在做查询时获取SearchView时引 入包错误经过长时间的尝试后才修正 2.滑动 ...
- 【Android】家庭记账本手机版开发报告三
一.说在前面 昨天 对第一天的框架结构进行了四方面的完善 今天 对界面显示和逻辑结构进行完善 问题 无 二.界面展示完善 1.使用可回收的列表recyclerView展示账单的信息,并设置数据项为卡片 ...
- WPS Office手机版调用接口代码指导帖之一(Android)
经常会有一些喜欢开发鼓捣的童鞋问我们,WPS Office手机版是否提供调用接口,希望在android中使用一个调用命令,直接调用WPS手机版来打开指定的DOC文件,而不用弹出一个程序可选列表(如果用 ...
- 手机版WEB开发经验分享,手机版网站开发注意事项,网站自适应,手机版网站自适应,移动安卓APP自适应
转自 http://my.oschina.net/cart/blog/282477 做前端开发不短了,用过jQuery Mobile jqMobi 也纯手工写过.. 最后总结如下: jQuery Mo ...
- Android实战项目——家庭记账本设计思路
经过三周左右的Android学习,实感只有上手开发才能有所提高.在此打算做一个家庭记账APP,同时巩固一下学到的东西并且弥补漏洞. 概述 记账是自古以来人类必不可少的一件事,从古代的算盘,到手写账本, ...
随机推荐
- 图解Mybatis框架原理及使用
1.前言 努力学习完ssm框架之后,终于也成功的把三大框架的使用以及配置文件细节忘得一干二净.为了努力捡起来以及方便今后的复习,决定写一篇博客记录一下. 本博客的所有分析都是在持久层接口以及接口中的方 ...
- 黑马客户管理系统(SSM)
黑马客户管理系统 1系统概述 1.1系统功能介绍 本系统后台使用SSM框架编写,前台页面使用当前主流的Bootstrap和jQuery框架完成页面信息展示功能(关于Bootstrap的知识,有兴趣的读 ...
- 对于文章的字母、单词、短语,(无用词表)的检索Java代码实现
日期:2019.5.9 博客期:073 星期四 今天软件工程课上,又做了测试,老师说我们的速度太慢了,实际上我也觉得自己很慢.老师说了这是我们的上一届的大二上半学期学习中的速度,所以呢?意思就是说我们 ...
- 六种方式实现hibernate查询,及IDE推荐
这些天过的好乱,也许是因为考完试了,心里有些松懈吧.也许是最近发生的事对我有些触动吧.感觉自己都已经不懂自己了.面对一些人的教导,我很感激.因为很多话都对我有非常大的帮助和启发,也让我除了做技术, ...
- mysql any和all的用法
1.ANY关键字假设any内部的查询语句返回的结果个数是三个,如:result1,result2,result3,那么, select ...from ... where a > any(. ...
- Vue的7属性-8方法-7指令
Vue的7属性: el属性 绑定id,用来指示vue编译器从什么地方开始解析 vue的语法,可以说是一个占位符 data属性 用来组织从view中抽象出来的属性,可以说将视图的数据抽象出来存放在dat ...
- 2-10 就业课(2.0)-oozie:10、伪分布式环境转换为HA集群环境
hadoop 的基础环境增强 HA模式 HA是为了保证我们的业务 系统 7 *24 的连续的高可用提出来的一种解决办法,现在hadoop当中的主节点,namenode以及resourceManager ...
- C++编程学习(十二) STL
一.简介 标准模板库STL,是一组模板类和函数.提供了: 1.容器.用于存储信息. 2.迭代器.用于访问容器中的信息. 3.算法.操作容器内容. 1.容器 STL有两种类型的容器类: (1)顺序容器 ...
- R 《回归分析与线性统计模型》page93.6
rm(list = ls()) #数据处理 library(openxlsx) library(car) library(lmtest) data = read.xlsx("xiti4.xl ...
- 4 GC算法与种类