今天练习了数据库的添加,学习了日期的获取
package com.example.meiri; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.example.meiri.db.PunchHelper; import java.text.SimpleDateFormat; import java.util.Date; public class record extends AppCompatActivity { private PunchHelper punchHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_record); // 声明 TextView et_date = findViewById(R.id.rd_tv_date); //日期 ImageView iv_back = findViewById(R.id.rd_iv_back); //返回 Button bt_punch = findViewById(R.id.rd_bt_punch); //打卡 EditText ed_keys = findViewById(R.id.rd_ed_keys); //关键字 EditText ed_text = findViewById(R.id.rd_ed_text); //内容 EditText ed_day = findViewById(R.id.rd_ed_days); //坚持天数 EditText ed_maxday = findViewById(R.id.rd_ed_maxday); //连续最长天数 // 时间显示 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyy年MM月MM日"); Date date = new Date(System.currentTimeMillis()); et_date.setText(simpleDateFormat.format(date)); // 返回 iv_back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(record.this, MainActivity.class); startActivity(intent); finish(); } }); bt_punch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String date = et_date.getText().toString().trim(); String keys = ed_keys.getText().toString().trim(); String text = ed_text.getText().toString().trim(); String maxday = ed_maxday.getText().toString().trim(); String day = ed_day.getText().toString().trim(); // 判断输入是否为空 if (!TextUtils.isEmpty(keys) && !TextUtils.isEmpty(text) && !TextUtils.isEmpty(maxday)){ punchHelper.add(date,keys,text,day,maxday); Intent intent1 = new Intent(record.this, MainActivity.class); startActivity(intent1); finish(); Toast.makeText(record.this, "打卡成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(record.this, "基本项目未填写完整", Toast.LENGTH_SHORT).show(); } } }); punchHelper = new PunchHelper(record.this); } }
日期
public class SimpleDateFormat extends DateFormat { // the official serial version ID which says cryptically // which version we're compatible with static final long serialVersionUID = 4774881970558875024L; // the internal serial version which says which version was written // - 0 (default) for version up to JDK 1.1.3 // - 1 for version from JDK 1.1.4, which includes a new field
标签:总结,text,每日,new,ed,date,import,android From: https://www.cnblogs.com/JJTyyds/p/17176901.html