每日打卡app
package com.example.clockappliction; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import com.example.clockappliction.DataBase.CRUD; import com.example.clockappliction.Information.Clock; import com.example.clockappliction.Information.Count; public class ClockActivity extends AppCompatActivity implements View.OnClickListener{ private EditText et_dk_date,et_dk_word,et_dk_summary,et_dk_maxday; private Button btn_dk_add; private TextView tv_dk_keep; @SuppressLint("MissingInflatedId") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_clock_in); tv_dk_keep = (TextView) findViewById(R.id.tv_dk_keep); Count count = new Count(); int keep = count.getCou(); count.toCou(); tv_dk_keep.setText("坚持天数"+ keep); et_dk_date = (EditText) findViewById(R.id.et_dk_date); et_dk_word = (EditText) findViewById(R.id.et_dk_word); et_dk_summary = (EditText) findViewById(R.id.et_dk_summary); et_dk_maxday = (EditText) findViewById(R.id.et_dk_maxday); btn_dk_add = (Button) findViewById(R.id.btn_dk_add); btn_dk_add.setOnClickListener(this); } @Override public void onClick(View view) { if (view==findViewById(R.id.btn_dk_add)){ CRUD crud = new CRUD(this); //获取输入框信息 Clock clock =new Clock(); clock.date = et_dk_date.getText().toString(); clock.word = et_dk_word.getText().toString(); clock.summary = et_dk_summary.getText().toString(); clock.maxday = et_dk_maxday.getText().toString(); Intent intent = getIntent(); String cid = intent.getStringExtra("cid"); Count count = new Count(); clock.cid = cid; clock.keep = String.valueOf(count.getCou()); crud.insertClock(clock); Toast.makeText(this, "打卡成功!", Toast.LENGTH_SHORT).show(); } } }
xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:background="#DDDDDD" tools:context=".ClockActivity"> <TextView android:id="@+id/tv_title3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_marginStart="98dp" android:layout_marginTop="98dp" android:text="每日打卡" android:textColor="#000" android:textSize="50sp" android:textStyle="bold" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/et_dk_date" android:hint="日期" android:layout_below="@+id/tv_title3" android:layout_marginTop="15dp" ></EditText> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/et_dk_word" android:hint="每日关键字" android:layout_below="@+id/et_dk_date" android:layout_marginTop="10dp" ></EditText> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/et_dk_summary" android:hint="每日总结" android:layout_below="@+id/et_dk_word" android:layout_marginTop="10dp" ></EditText> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/et_dk_maxday" android:hint="连续最长天数" android:layout_below="@+id/et_dk_summary" android:layout_marginTop="10dp" ></EditText> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btn_dk_add" android:text="打卡" android:textSize="30dp" android:layout_below="@+id/et_dk_maxday" android:layout_marginTop="20dp" android:layout_marginLeft="120dp" ></Button> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tv_dk_keep" android:layout_below="@+id/btn_dk_add" android:textSize="30dp" ></TextView> </RelativeLayout>
用于插入打卡信息的函数
public void insertClock(Clock clock){ SQLiteDatabase db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(Clock.DATE,clock.date); values.put(Clock.WORD,clock.WORD); values.put(Clock.SUMMARY,clock.summary); values.put(Clock.KEEP,clock.keep); values.put(Clock.MAXDAY,clock.maxday); values.put(Clock.CID,clock.cid); db.insert(Clock.TABLE,null,values); db.close(); }