zoukankan      html  css  js  c++  java
  • 2.24账本开发5

    new_cost

    package com.example.zhangbengapp;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.content.ContentValues;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.view.Gravity;
    import android.view.View;
    import android.widget.DatePicker;
    import android.widget.EditText;
    import android.widget.Toast;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    public class new_cost extends AppCompatActivity {
        private DBHelper helper;
        private EditText et_cost_title;
        private EditText et_cost_money;
        private DatePicker dp_cost_date;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_new_cost);
            initView();
        }
    
        private void initView() {
            helper = new DBHelper(new_cost.this);
            et_cost_title = findViewById(R.id.et_cost_title);
            et_cost_money = findViewById(R.id.et_cost_money);
            dp_cost_date = findViewById(R.id.dp_cost_date);
    
        }
    
    
    
        public void okButton(View view) {
            String titleStr = et_cost_title.getText().toString().trim();
            String moneyStr = et_cost_money.getText().toString().trim();
            String dateStr = dp_cost_date.getYear() + "-" + (dp_cost_date.getMonth() + 1) + "-"
                    + dp_cost_date.getDayOfMonth();//这里getMonth会比当前月份少一个月,所以要+1
            if ("".equals(moneyStr)) {//可以不填写Title但是不能不填金额
                Toast toast = Toast.makeText(this, "请填写金额", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else {
                SQLiteDatabase db = helper.getWritableDatabase();
                ContentValues values = new ContentValues();
                values.put("Title", titleStr);
                values.put("Money", moneyStr);
                values.put("Date", dateStr);
                long account = db.insert("account", null, values);
                if (account > 0) {
                    Toast toast = Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.show();
                    setResult(1);
                    finish();
                } else {
                    Toast toast = Toast.makeText(this, "请重试", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.CENTER, 0, 0);
                    toast.show();
                    db.close();
                }
                setResult(1);
                finish();
            }
    
        }
    }
  • 相关阅读:
    游戏运营-三节课
    游戏运营-游戏付费
    游戏运营--资深
    django 导出csv
    django-分页
    django-中间件
    django-缓存
    django post 与get请求理解
    django 中遇到的问题
    Linux下使用XAMPP
  • 原文地址:https://www.cnblogs.com/dty602511/p/14913161.html
Copyright © 2011-2022 走看看