今天實現的內容有:添加帳本信息,我的頭像的切換,密碼的修改,退出登陸。java
添加帳本信息有三個功能:android
①記一筆支出項目app
②記一筆收入項目ide
③清空全部項目佈局
在此期間遇到的困難有:Activity與Fragment之間數值的傳遞問題,我利用Bundle對象來進行傳值,可是佈局文件中fragment裏的name=「Account_Fragment」,這裏暫時沒有想到如何傳值。學習
所以暫時將name="Find_Message"這個還未改變的一個fragment,當再次點擊Account圖標時,就能夠傳進去參數。ui
未解決的事:spa
①記完帳本後,按日期排序一直不對code
②初始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(); } } }