package com.example.jizhangben; import android.app.Activity; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.DatePicker; import android.widget.EditText; import androidx.annotation.Nullable; public class addcost extends Activity implements View.OnClickListener { private EditText title_et; private EditText money_et; private DatePicker date_dp; private Button tijiao_btn; private Button back_btn; private CostDB costDB; private SQLiteDatabase dbwriter; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.addcost); title_et=(EditText)findViewById(R.id.et_title); money_et=(EditText)findViewById(R.id.et_money); date_dp=(DatePicker)findViewById(R.id.dp_data); tijiao_btn=(Button)findViewById(R.id.bt_tijiao); back_btn=(Button)findViewById(R.id.bt_back); tijiao_btn.setOnClickListener(this); back_btn.setOnClickListener(this); costDB =new CostDB(this); dbwriter = costDB.getWritableDatabase(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bt_tijiao: costBean costBean1=new costBean(); costBean1.costTitle=title_et.getText().toString(); costBean1.costMoney=money_et.getText().toString(); costBean1.costDate=date_dp.getYear()+"-"+(date_dp.getMonth()+1)+"-"+date_dp.getDayOfMonth(); costDB.insertCost(costBean1); finish(); break; case R.id.bt_back: finish(); break; } } }