今天学习了数据的添加,和本地日期的获取。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/grey7d"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="日期" android:layout_marginTop="30dp" android:textSize="25sp" android:textColor="#000000" android:layout_weight="1"/> <EditText android:id="@+id/timeET" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="输入日期" android:layout_marginTop="30dp" android:textSize="20sp" android:textColor="#2196F3" android:layout_weight="2"/> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="每日关键字:" android:textSize="25sp" android:layout_marginTop="30dp" android:textColor="#000000" android:layout_weight="1"/> <EditText android:id="@+id/key_word" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:hint="学习或者娱乐" android:textSize="20sp" android:textColor="#2196F3" android:layout_weight="2" android:inputType="textWebPassword"/> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="每日总结:" android:layout_marginTop="30dp" android:textSize="25sp" android:textColor="#000000" android:layout_weight="1"/> <EditText android:id="@+id/zongjie" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="总结" android:layout_marginTop="30dp" android:textSize="20sp" android:textColor="#2196F3" android:layout_weight="2"/> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="坚持天数:" android:layout_marginTop="30dp" android:textSize="25sp" android:textColor="#000000" android:layout_weight="1"/> <EditText android:id="@+id/jianchi" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="数字" android:layout_marginTop="30dp" android:textSize="20sp" android:textColor="#2196F3" android:layout_weight="2"/> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="坚持最长时间:" android:layout_marginTop="30dp" android:textSize="25sp" android:textColor="#000000" android:layout_weight="1"/> <EditText android:id="@+id/max_day" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="天数" android:layout_marginTop="30dp" android:textSize="20sp" android:textColor="#2196F3" android:layout_weight="2"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:textColor="#000000" android:layout_marginTop="40dp" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:textSize="25sp" android:textAllCaps="false" android:text="确认" android:id="@+id/redays" android:layout_width="match_parent" android:layout_height="wrap_content"/> <Button android:textColor="#000000" android:layout_marginTop="20dp" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:textSize="25sp" android:textAllCaps="false" android:text="取消" android:id="@+id/backs" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout>
package com.example.clock; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.icu.text.SimpleDateFormat; import android.os.Build; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.example.clock.db.DatabaseHelper; import com.example.clock.db.DbHelper; import com.example.clock.jiben.DaKa; import com.example.clock.jiben.User; import java.security.PrivateKey; import java.util.ArrayList; import java.util.Date; public class RecordFrg extends AppCompatActivity { private DbHelper mSQLite; @RequiresApi(api = Build.VERSION_CODES.N) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_record_frg); //找到各个控件 Button btn_ready = findViewById(R.id.redays); Button btn_back = findViewById(R.id.backs); TextView dates = findViewById(R.id.timeET); EditText ed_Key = findViewById(R.id.key_word); EditText ed_zongjie = findViewById(R.id.zongjie); EditText ed_jianchi= findViewById(R.id.jianchi); EditText ed_max = findViewById(R.id.max_day); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); Date date = new Date(System.currentTimeMillis()); dates.setText(simpleDateFormat.format(date)); //注册监听事件 btn_ready.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //获取输入的用户名和密码 String datess = dates.getText().toString().trim(); String keyword = ed_Key.getText().toString().trim(); String zj =ed_zongjie.getText().toString().trim(); String jc = ed_jianchi.getText().toString().trim(); String max=ed_max.getText().toString().trim(); //获取数据库数据,判断用户名是否已存在 /* ArrayList<DaKa> data = mSQLite.getAllDATA(); boolean flag = false; for(int i = 0; i < data.size(); i++){ DaKa userdata = data.get(i); if(.equals(userdata.getName())){ flag = true; break; }else{ flag = false; } }*/ //判断用户名和密码是否为空 if(!TextUtils.isEmpty(datess)&&!TextUtils.isEmpty(keyword)){ mSQLite.insert(datess, keyword,zj,jc,max); Intent intent1 = new Intent(RecordFrg.this, MainActivity.class); startActivity(intent1); finish(); Toast.makeText(RecordFrg.this, "打卡成功", Toast.LENGTH_SHORT).show(); } else{ Toast.makeText(RecordFrg.this, "内容不可以为空", Toast.LENGTH_SHORT).show(); } } }); //监听返回按钮 btn_back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent2 = new Intent(RecordFrg.this, MainActivity.class); startActivity(intent2); finish(); } }); mSQLite = new DbHelper(RecordFrg.this); } }
标签:总结,findViewById,ed,每日,3.3,new,import,android,id From: https://www.cnblogs.com/syhxx/p/17176900.html