安卓开发实战-记账本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 ...
随机推荐
- SpringBoot系列之自定义starter实践教程
SpringBoot系列之自定义starter实践教程 Springboot是有提供了很多starter的,starter翻译过来可以理解为场景启动器,所谓场景启动器配置了自动配置等等对应业务模块的一 ...
- 跟我一起学QT_QT标准对话框_字体选择框
标准对话框 QT的标准对话框分为以下几种 颜色对话框 文件对话框 字体对话框 输入对话框 消息对话框 进度对话框 错误信息对话框 向导对话框 字体选择框 字体选择框位于 QFontDialog 类中 ...
- 1070 结绳 (25 分)C语言
给定一段一段的绳子,你需要把它们串成一条绳.每次串连的时候,是把两段绳子对折,再如下图所示套接在一起.这样得到的绳子又被当成是另一段绳子,可以再次对折去跟另一段绳子串连.每次串连后,原来两段绳子的长度 ...
- 用积分方法求K次方和数列公式
这是我很早以前在高中时发现的一个通用计算K次方和数列公式的方法,很特别的地方是用了微积分中的积分方法.目前我还没有发现有谁提出和我一样的方法,如果哪位读者有相关发现,麻烦告知我. 大家很多人都知道高斯 ...
- windebug(转载别人的节选)
问题一:WinDBG分X86和X64两个版本 如果你用的是32位的WinDBG,那直接打开就行:你如果用的是64位的版本,那么如果调试64位代码也直接打开,如果调试x86的代码,要使用Wow64下的W ...
- schedule of 2016-09-12~2016-09-18(Monday~Sunday)——1st semester of 2nd Grade
2016/9/12 Monday 1.send present to Teacher Wei&hu 2.make ppt for 1st database 2.0 meeting for al ...
- eclipse maven工程错误总汇
1.问题: Target runtime Apache Tomcat v7.0 is not defined 解决方法: right click on your project & ...
- Java Linked集合的简单介绍和常用方法的使用
LinkedList的简单介绍 java.util.LinkedList 集合数据存储的结构是链表结构.LinkedList是一个双向链表在实际开发中,对一个集合元素的添加和删除,经常涉及到首尾操作, ...
- 单调队列优化 dp
The only difference between easy and hard versions is the constraints. Vova likes pictures with kitt ...
- 读取Core下的appsettings.json的值的时候中文乱码
这个百度一下一大堆,我就用的这个:然后重新生成一次就好了. 2.有的是更改VS的什么高级保存之类的,我记得之气设置过, 然后就是:这篇文章