zoukankan      html  css  js  c++  java
  • 2021/2/8

    记录数据,将数据放进记账本

    package com.example.bookkeeping;
    
    import android.content.ContentValues;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.RadioButton;
    import android.widget.Toast;
    
    import androidx.annotation.Nullable;
    import androidx.appcompat.app.AppCompatActivity;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class jilu extends AppCompatActivity {
        private MyDatabaseHelper dbHelper;
    
        private EditText editText1;
        private EditText editText2;
        private EditText editText3;
        String shouru="";
        String zhichu="";
    
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 ");// HH:mm:ss
        //获取当前时间
        Date date = new Date(System.currentTimeMillis());
    
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_jilu);
    
            dbHelper=new MyDatabaseHelper(this,"zhangben.db",null,4);
            dbHelper.getWritableDatabase();
    
            editText1 = (EditText) findViewById(R.id.edit_11);
            editText2 = (EditText) findViewById(R.id.edit_12);
            editText3 = (EditText) findViewById(R.id.edit_13);
    
            final RadioButton sex1=(RadioButton) findViewById(R.id.radioButton1);//获取单选按钮组
            final RadioButton sex2=(RadioButton) findViewById(R.id.radioButton2);//获取单选按钮组
    
    
            Button button=(Button)findViewById(R.id.button);
    
            editText3=(EditText)findViewById(R.id.edit_13);
            editText3.setText(simpleDateFormat.format(date));
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    SQLiteDatabase db=dbHelper.getWritableDatabase();
                    ContentValues values=new ContentValues();
    
                    String m1=editText1.getText().toString();
                    String m2=editText2.getText().toString();
                    String m3=editText3.getText().toString();
    
                    values.put("原因",m1);
                    values.put("金额",m2);
                    values.put("时间",m3);
                    if(sex1.isChecked()){
                        shouru="收入";
                        values.put("盈亏",shouru);
                    }
                    if(sex2.isChecked()){
                        zhichu="支出";
                        values.put("盈亏",zhichu);//存性别
                    }
    
                    if(m1.equals("")||m2.equals("")||m3.equals(""))
                    {
                        Toast.makeText(jilu.this, "信息不全,请补充", Toast.LENGTH_SHORT).show();
                    }
                    else{
                        db.insert("zhangben",null,values);
                        //注意别漏掉
                        values.clear();
                        Toast.makeText(jilu.this, "保存成功", Toast.LENGTH_SHORT).show();
                        editText1.setText("");//保存成功清空学号和姓名信息
                        editText2.setText("");
                        editText3.setText(simpleDateFormat.format(date));
                    }
                }
            });
        }
    }
  • 相关阅读:
    maven打包时跳过测试
    idea打包SpringBoot项目打包成jar包和war
    idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到
    idea16使用maven命令clean、编译、打包jar或者war
    关于spring boot jar包与war包的问题
    spring boot-html和templates
    spring boot之访问静态页面
    奇虎360选择IPO “壳概念”很受伤
    不怕成本高,不怕卖的少。高端形象一定要打起来。
    ddddd
  • 原文地址:https://www.cnblogs.com/qiangini/p/14905034.html
Copyright © 2011-2022 走看看