首页 > 其他分享 >6.17 7

6.17 7

时间:2024-06-17 23:55:48浏览次数:21  
标签:frag void 6.17 accountBean record import view

package com.zhen.accountbook.frag_record;

import android.inputmethodservice.KeyboardView;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.*;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.zhen.accountbook.R;
import com.zhen.accountbook.db.AccountBean;
import com.zhen.accountbook.db.DBManager;
import com.zhen.accountbook.db.TypeBean;
import com.zhen.accountbook.utils.BeiZhuDialog;
import com.zhen.accountbook.utils.KeyBoardUtils;
import com.zhen.accountbook.utils.SelectTimeDialog;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 记录页面当中的支出模块
 */
public class OutFragment extends Fragment implements View.OnClickListener {
    KeyboardView keyboardView;
    EditText moneyEt;
    ImageView typeIV;
    TextView typeTv, beizhuTv, timeTv;
    GridView typeGv;
    List<TypeBean> typeList;
    TypeBaseAdapter adapter;
    AccountBean accountBean;//将需要插入到记账本的数据保存成对象的格式

    @Override
    public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        accountBean = new AccountBean();
        accountBean.setTypename("其他");
        accountBean.setsImageId(R.mipmap.ic_qita_fs);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_outcome, container, false);
        initView(view);
        setInitTime();
        //给GridView填充数据
        loadDataToGV();
        setGVListener();//设置GridView每一项的点击事件
        return view;
    }

    //获取当前时间,显示在timeTv上
    private void setInitTime() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        timeTv.setText(sdf.format(date));
        accountBean.setTime(sdf.format(date));
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        accountBean.setYear(year);
        accountBean.setMonth(month);
        accountBean.setDay(day);
    }

    private void setGVListener() {
        typeGv.setOnItemClickListener((adapterView, view, i, l) -> {
            adapter.selectPos = i;
            adapter.notifyDataSetChanged();
            TypeBean typeBean = typeList.get(i);
            //点击每一项时,上边会刷新所选中的图像
            String typename = typeBean.getTypename();
            typeTv.setText(typename);
            accountBean.setTypename(typename);
            int sImageId = typeBean.getSImageId();
            typeIV.setImageResource(sImageId);
            accountBean.setsImageId(sImageId);
        });
    }

    public void loadDataToGV() {
        typeList = new ArrayList<>();
        adapter = new TypeBaseAdapter(getContext(), typeList);
        typeGv.setAdapter(adapter);
        //获取数据库当中的数据源
        List<TypeBean> outlist = DBManager.getTypeList(0);
        typeList.addAll(outlist);
        adapter.notifyDataSetChanged();
        typeTv.setText("其他");
        typeIV.setImageResource(R.mipmap.ic_qita_fs);
    }

    private void initView(View view) {
        keyboardView = view.findViewById(R.id.frag_record_keyboard);
        moneyEt = view.findViewById(R.id.frag_record_et_money);
        typeIV = view.findViewById(R.id.frag_record_iv);
        typeGv = view.findViewById(R.id.frag_record_gv);
        typeTv = view.findViewById(R.id.frag_record_tv_type);
        beizhuTv = view.findViewById(R.id.frag_record_tv_beizhu);
        timeTv = view.findViewById(R.id.frag_record_tv_time);
        beizhuTv.setOnClickListener(this);
        timeTv.setOnClickListener(this);
        //显示自定义键盘
        KeyBoardUtils boardUtils = new KeyBoardUtils(keyboardView, moneyEt);
        boardUtils.showKeyBoard();
        //设置接口,监听确定按钮   被点击
        boardUtils.setOnEnsureListener(() -> {
            // 获取输入钱数
            String moneyStr = moneyEt.getText().toString();
            if (TextUtils.isEmpty(moneyStr) || moneyStr.equals("0")) {
                getActivity().finish();
                return;
            }
            float money = Float.parseFloat(moneyStr);
            accountBean.setMoney(money);
            //获取记录的信息,将信息保存到数据库中
            saveAccountToDB();
            //返回上一级页面
            getActivity().finish();
        });
    }

    private void saveAccountToDB() {
        accountBean.setKind(0);
        DBManager.insertItemToAccounttb(accountBean);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.frag_record_tv_beizhu) {
            showBZDialog();
        } else if (v.getId() == R.id.frag_record_tv_time) {
            showTimeDialog();
        }
        //跳转到时间选择界面
    }

    private void showTimeDialog() {
        SelectTimeDialog dialog = new SelectTimeDialog(getContext());
        dialog.show();
    }

    //弹出备注对话框
    public void showBZDialog() {
        BeiZhuDialog dialog = new BeiZhuDialog(getContext());
        dialog.show();
        dialog.setDialogSize();
        dialog.setOnEnsureListener(() -> {
            String msg = dialog.getEditText();
            if (!TextUtils.isEmpty(msg)) {
                beizhuTv.setText(msg);
                accountBean.setBeizhu(msg);
            }
            dialog.cancel();
        });
    }
}

 

标签:frag,void,6.17,accountBean,record,import,view
From: https://www.cnblogs.com/zzqq1314/p/18253473

相关文章

  • 6.17 6
    packagecom.zhen.accountbook.utils;importandroid.app.Dialog;importandroid.content.Context;importandroid.os.Bundle;importandroid.text.TextUtils;importandroid.view.View;importandroid.widget.Button;importandroid.widget.EditText;importandroid......
  • 6.17 8
    packagecom.zhen.accountbook.adapter;importandroid.content.Context;importandroid.view.LayoutInflater;importandroid.view.View;importandroid.view.ViewGroup;importandroid.widget.BaseAdapter;importandroid.widget.ImageView;importandroid.widget.T......
  • 6.17 10
    <?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layou......
  • 6.17 9
    <?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="wrap_con......
  • 2024.6.17鲜花/错误的号码
    XY星的星际新闻报一直不太畅销,所以报纸上会有一些广告,毕竟星际新闻局的非机器人员工也得吃饭。有一则广告是这样的:【数据删除】研学基地位于【数据删除】,该研学基地致力于让学生体验一个幻想纪前的生活并培养学生不借助现代高科技的群居生活能力。该研学基地将于幻想历元年六......
  • 6.17 学习心得
    这本书讲述了几十年前软件专案管理问题与经验,作者将大型系统开发比作一个焦油坑,我原本以为软件开发还是比较容易的,有了新想法,就会有新的软件产品出现,但是却不知道项目不能满足目标、进度、预算的要求,就不能成为一个好项目。程序,通过不同的途径转变成不同的产物,使之变得更有用,成本......
  • dart最新2024.06.17
    import'package:flutter/material.dart';voidmain(){runApp(constMyApp());}classMyAppextendsStatelessWidget{constMyApp({super.key});@overrideWidgetbuild(BuildContextcontext){returnconstMaterialApp(title:&......
  • 云原生周刊:Harbor v2.11 版本发布 | 2024.6.17
    开源项目推荐DeschedulerDescheduler是一个工具,可用于优化Kubernetes集群中Pod的部署位置。它可以找到可以移动的Pod,并将其驱逐,让默认调度器将它们重新调度到更合适的节点上。ProwlerProwler是一款适用于AWS、Azure、GCP和Kubernetes的开源安全工具,用于进行安全评......
  • Java速成笔记 2024.6.17版
    变量:可以变化的容器不同变量可以存储不同类型的值变量声明方法:变量类型变量名=初始值;E.G.inta=1;变量类型:整型:intlong浮点数:floatdouble布尔:boolean字符串:String字符:char变量命名注意事项:不能重名不能以数字开头常量:关键字:final语法:finalfl......
  • 6.17
    实验二SQL语言的使用一、实验目的:掌握使用SQL语言进行各种查询的操作和视图的操纵方法。二、实验要求:在现有的数据库上进行各种查询操作,对视图的创建、使用等操作。三、实验步骤:1、开始→程序→MicrosoftSQLServer→SQLServerManagementStudio。2、在“连接到服......