安卓开发实战-记账本APP(四)
今天实现的内容有:添加账本信息,个人头像的切换,密码的修改,退出登录。
添加账本信息有三个功能:
①记一笔支出项目
②记一笔收入项目
③清空所有项目
在此期间遇到的困难有:Activity与Fragment之间数值的传递问题,我利用Bundle对象来进行传值,但是布局文件中fragment里的name=“Account_Fragment”,这里暂时没有想到如何传值。
因此暂时将name="Find_Message"这个还未改变的一个fragment,当再次点击Account图标时,就可以传进去参数。
未解决的事:
①记完账本后,按日期排序一直不对
②初始Fragment没办法传参
明天要做的事:
先将上述问题解决,在设置长按项目进行单独删除。
统计总的收入与支出的对比
找到合适的图标进行替换
学习hellochart,将数据以饼状图展示。
今日成果:

点击更换头像:会有几个头像供选择

当点击后自动跳回个人信息界面:

其次是更换密码:需要输入原密码与新密码

再者就是记账的页面:有支出,收入,删除所有,支出的会显示红色,收入的会显示绿色

当点击收入时,会弹出一个框来进行记账

同理,当点击支出时,也会弹出一个框

当点击删除所有时,会将所有账目全部删除。
Account_Fragment:记账的Fragment
package com.example.countbook; import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton; import androidx.annotation.Nullable; import java.util.ArrayList;
import java.util.List; public class Account_Fragment extends Fragment {
private List<Account> list;
private AccountOperator accountOperator;
private AccountAdapter accountAdapter;
Button btn_shouru;
Button btn_zhichu;
Button btn_delete;
Bundle bundle;
String username;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bundle=getArguments();
username=bundle.getString("username");
//Log.i("username",username);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.account_fragment,null);
btn_shouru=(Button)view.findViewById(R.id.btn_shouru);
btn_zhichu=(Button)view.findViewById(R.id.btn_zhichu);
btn_delete=(Button)view.findViewById(R.id.btn_delete); accountOperator=new AccountOperator(view.getContext());
list=new ArrayList<>();
ListView AccountList=(ListView)view.findViewById(R.id.lv_main);
inin(username);
accountAdapter=new AccountAdapter(view.getContext(),list);
AccountList.setAdapter(accountAdapter);
btn_zhichu.setOnClickListener(l);
btn_shouru.setOnClickListener(l);
btn_delete.setOnClickListener(l);
return view;
}
View.OnClickListener l=new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_zhichu:
AlertDialog.Builder builder=new AlertDialog.Builder(getView().getContext());
LayoutInflater inflater=LayoutInflater.from(getView().getContext());
View viewDialog=inflater.inflate(R.layout.new_cost_data,null);
final EditText content=(EditText)viewDialog.findViewById(R.id.et_cost_content);
final DatePicker data=(DatePicker)viewDialog.findViewById(R.id.dp_cost_data);
final EditText money=(EditText)viewDialog.findViewById(R.id.et_cost_money);
final RadioButton rb1=(RadioButton)viewDialog.findViewById(R.id.rb1);
final RadioButton rb2=(RadioButton)viewDialog.findViewById(R.id.rb2);
final RadioButton rb3=(RadioButton)viewDialog.findViewById(R.id.rb3);
final RadioButton rb4=(RadioButton)viewDialog.findViewById(R.id.rb4); builder.setView(viewDialog);
builder.setTitle("New Cost");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Account bean=new Account();
bean.author=username;
bean.content=content.getText().toString();
bean.money=Integer.parseInt(money.getText().toString());
bean.date=data.getYear()+"-"+(data.getMonth()+1)+"-"+data.getDayOfMonth();
if(rb1.isChecked()){
bean.title=rb1.getText().toString();
}else if(rb2.isChecked()){
bean.title=rb2.getText().toString();
}else if(rb3.isChecked()){
bean.title=rb3.getText().toString();
}else if(rb4.isChecked()){
bean.title=rb4.getText().toString();
}
accountOperator.insert(bean);
list.add(bean);
accountAdapter.notifyDataSetChanged();
}
});
builder.setNegativeButton("Cancel",null);
builder.create().show();
break; case R.id.btn_shouru:
AlertDialog.Builder builder2=new AlertDialog.Builder(getView().getContext());
LayoutInflater inflater2=LayoutInflater.from(getView().getContext());
View viewDialog2=inflater2.inflate(R.layout.new_income_data,null);
final EditText content2=(EditText)viewDialog2.findViewById(R.id.et_income_content);
final DatePicker data2=(DatePicker)viewDialog2.findViewById(R.id.dp_income_data);
final EditText money2=(EditText)viewDialog2.findViewById(R.id.et_income_money);
final RadioButton frb1=(RadioButton)viewDialog2.findViewById(R.id.rb1);
final RadioButton frb2=(RadioButton)viewDialog2.findViewById(R.id.rb2);
final RadioButton frb3=(RadioButton)viewDialog2.findViewById(R.id.rb3); builder2.setView(viewDialog2);
builder2.setTitle("New InCome");
builder2.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Account bean=new Account();
bean.author=username;
bean.content=content2.getText().toString();
bean.money=Integer.parseInt(money2.getText().toString());
bean.date=data2.getYear()+"-"+(data2.getMonth()+1)+"-"+data2.getDayOfMonth();
if(frb1.isChecked()){
bean.title=frb1.getText().toString();
}else if(frb2.isChecked()){
bean.title=frb2.getText().toString();
}else if(frb3.isChecked()){
bean.title=frb3.getText().toString();
}
accountOperator.insert(bean);
list.add(bean);
accountAdapter.notifyDataSetChanged();
}
});
builder2.setNegativeButton("Cancel",null);
builder2.create().show();
break;
case R.id.btn_delete:
accountOperator.deleteall(username);
list.clear();
accountAdapter.notifyDataSetChanged();
break; }
}
}; private void inin(String author) {
Cursor cursor= (Cursor) accountOperator.findall(author);
if(cursor!=null){
while(cursor.moveToNext()){
Account bean=new Account();
bean.content=cursor.getString(cursor.getColumnIndex("content"));
bean.money=cursor.getInt(cursor.getColumnIndex("money"));
bean.date=cursor.getString(cursor.getColumnIndex("date"));
bean.title=cursor.getString(cursor.getColumnIndex("title"));
list.add(bean);
}
cursor.close();
}
}
}
安卓开发实战-记账本APP(四)的更多相关文章
- 安卓开发实战-记账本APP(六)
记账本APP开发---终结篇 昨天的动态数字录屏奉上:在抖音上拍了一个(ps:欢迎点赞) https://v.douyin.com/poEjmG/ 今天将图表的内容进行了制作,我用的是MPChart的 ...
- 安卓开发实战-记账本APP(三)
本次实现的是有关登录,注册和整体页面的改观,实现下方选项导致页面的切换效果. 利用到的技术有Sqlite数据库的增删改查,与fragment实现.由于暂时没有找到合适的图标,先借用微信的图标暂代一下. ...
- 安卓开发实战-记账本APP(五)
今天将昨天剩余的bug修复,并且完成图标的美化,设置长按删除,模仿支付宝实现金额的动态增加. ①将昨天的布局进行了修改:之前是fragment,改成FrameLayout布局,不再设置name,进而在 ...
- android开发实战-记账本APP(二)
继昨天的开发,继续完成今天的内容. (一)开始构建一些业务逻辑,开始构建记账本的添加一笔记账的功能. ①对fab按钮的click时间进行修改,创建一个AlertDialog.Builder对象,因此我 ...
- android开发实战-记账本APP(一)
记账本开发流程: 对于一个记账本的初步开发而言,我实现的功能有: ①实现一个记账本的页面 ②可以添加数据并更新到页面中 ③可以将数据信息以图表的形式展现 (一)首先,制作一个记账本的页面. ①在系统自 ...
- Android开发实战——记账本(2)
开发日志(2)——Bean目录以及数据库 首先编写一些自己生成的数据进行测试,看一下能否显示在模拟器上.那前提就是先写出bean目录,这和之前学的Javaweb步骤差不多.bean目录有三个变量事件. ...
- Android开发实战——记账本(4)
开发日志(4)——MainActivity 在MainActivity中编写了几个方法.首先,点击账本的一条记录可以选择删除他,然后重写了fab,使之在点击他后能够添加记录.还写了删除全部记录的方法. ...
- Android开发实战——记账本(6)
开发日志——(6) 今天将app签名打包,并部署在了真机上.真机上的截图: 运行成功:
- Android开发实战——记账本(5)
开发日志——(5) 今天打算将图标的功能实现,将打开图表的选项放在右上方,所以重写MainActivity中的onOptionsItemSelected方法.增添Chart选项 public ...
随机推荐
- 在Asp.Net Core中使用ModelConvention实现全局过滤器隔离
从何说起 这来自于我把项目迁移到Asp.Net Core的过程中碰到一个问题.在一个web程序中同时包含了MVC和WebAPI,现在需要给WebAPI部分单独添加一个接口验证过滤器IActionFil ...
- vc++栈的简单实现
栈的数据类型是先进后出 #ifndef __MYSTACK__ #define __MYSTACK__ #include <Windows.h> typedef struct Node { ...
- $Poj1723/AcWing123\ Soldiers$ 排序
$Poj$ $AcWing$ $Description$ $Sol$ 分别处理$x$坐标和$y$坐标.$y$坐标显然很好处理,就是排个序然后取中位数就好了.$x$没有$y$那么直接叭.所以我首先写了个 ...
- linux mysql 5.7.20 部署脚本+备份脚本
一.官网下载源码包 源码包:mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz 检查环境,卸载老版本mysql 二.自动部署脚本 进入文件目录,执行脚本 #!/bin ...
- Markdown破解及汉化
首先,附上用到的资源链接: 链接:https://pan.baidu.com/s/1ULvvCPcCv_P3KyD9ajXUjQ 提取码:5fkb 第一步 直接解压就可以,解压后运行该程序,会出现下图 ...
- docker-网桥
使用桥接网络 在网络方面,桥接网络是链路层设备,它在网络段之间转发流量. 网桥可以是硬件设备或在主机内核中运行的软件设备. Docker而言,桥接网络使用软件桥接器,该软件桥接器允许连接到同一桥接网络 ...
- 30.strftime参数
附:strftime参数 strftime(format[, tuple]) -> string 将指定的struct_time(默认为当前时间),根据指定的格式化字符串输出 python中时间 ...
- KMP 和 扩展KMP
KMP:在主串S中找子串T的位置KMP算法的时间复杂度O(|S|+|T|). #define maxn 1000 char s[maxn],t[maxn];//s为主串,t为子串 int net[ma ...
- 初始 Kafka Consumer 消费者
温馨提示:整个 Kafka 专栏基于 kafka-2.2.1 版本. 1.KafkaConsumer 概述 根据 KafkaConsumer 类上的注释上来看 KafkaConsumer 具有如下特征 ...
- GeneXus 16 如何实现自动化测试和发布
CI/CD(持续集成/持续发布)是一种软件开发策略,以使公司能够尽可能快速.高效地给客户发布新功能.为了能够实现CI/CD,就需要通过PipeLine对整个软件过程进行一系列的节点管理,必须将每个阶段 ...