zoukankan      html  css  js  c++  java
  • 第二阶段冲刺-10

    昨天制作了一个自定义的控件,可以实现,对时间的ViewText进行侦听,当点击时弹出自定义框,选择获取,年月日,并更改数据库方法

    遇到的问题:所用的数据库查询方法使用不够熟悉,只能通过查询出结果之后通过if语句进行处理。

    今天打算做:对项目进行整合,将所有实现的功能加入到项目中。

     public void showDateDialog() {
            mView = View.inflate(this, R.layout.date_dialog, null);
    
            np1 = (NumberPicker) mView.findViewById(R.id.np1);
            np2 = (NumberPicker) mView.findViewById(R.id.np2);
    
            //获取当前日期
            Calendar c = Calendar.getInstance();
    //
            final int year =  c.get(Calendar.YEAR);
            final int month1 = c.get(Calendar.MONTH)+1;//月份是从0开始算的
    //        final int day = c.get(Calendar.DAY_OF_MONTH);
            //获取当前的记账日期
    
    
            //设置年份
            np1.setMaxValue(2999);
            np1.setValue(year); //中间参数 设置默认值
            np1.setMinValue(2000);
    
    
    
            //设置月份
            np2.setMaxValue(12);
            np2.setValue(month1);
            np2.setMinValue(1);
    
    
    
    
    
    
    
            new AlertDialog.Builder(MainActivity.this).setTitle("请选择时间")
                    .setView(mView)
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
    
                            int months = np2.getValue();
    
                            month.setText( year + "年"+months + "月" );
                            dialog.dismiss();
                        }
                    })
                    .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    })
                    .show();
        }
    
        public float Query(String year1,String month,String type1) {
            db = helper_person.getWritableDatabase();
            float m =0;
            Cursor cursor = db.query("student", null, "month=?",new String[]{month}, null, null, null);
            while (cursor.moveToNext()) {
    
                String money = cursor.getString(2);
                String type = cursor.getString(3);
                String year = cursor.getString(4);
                if (year.equals(year1))
                {
                    if (type.equals(type1))
                    {
                        m = Float.parseFloat(money);
                    }
                }
            }
            db.close();
            return m;
        }
    

      

  • 相关阅读:
    晒一下我的统一网站管理平台
    走向DBA[MSSQL篇] 从SQL语句的角度 提高数据库的访问性能
    XSS跨站脚本实例
    关于开源的一点看法
    晒一下我的监控系统
    走向DBA[MSSQL篇] 详解游标
    【linux+C】新征程 linux下C编程
    走向DBA[MSSQL篇] 针对大表 设计高效的存储过程【原理篇】 附最差性能sql语句进化过程客串
    晒一下我的web过滤器
    分享新出炉的微软派工具 你,值得拥有
  • 原文地址:https://www.cnblogs.com/1gaoyu/p/10999822.html
Copyright © 2011-2022 走看看