3.26

所花时间:4小时

代码量:118

博客篇:1

每日学习记录功能实现:

package com.example.studyapplication;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.sql.SQLException;

public class addRecord extends AppCompatActivity implements View.OnClickListener {

    private EditText ed_starttime;
    private EditText ed_endtime;
    private EditText ed_record;
    private Button bt_add_record;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_record);
        ed_starttime = findViewById(R.id.ed_starttime);
        ed_endtime = findViewById(R.id.ed_endtime);
        ed_record  = findViewById(R.id.ed_record);
        bt_add_record = findViewById(R.id.bt_add_record);
        bt_add_record.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String starttime = ed_starttime.getText().toString();
                String endtime = ed_endtime.getText().toString();
                String record = ed_record.getText().toString();
                String id,name,unit;
                SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE);
                id = sharedPreferences.getString("id","");
                name = sharedPreferences.getString("name","");
                unit = sharedPreferences.getString("unit","");
                Record r = new Record();
                r.setId(id);
                r.setName(name);
                r.setUnit(unit);
                r.setStarttime(starttime);
                r.setEndtime(endtime);
                r.setRecord(record);
                Dao d =new Dao();
                try {
                    d.addRecord(r);
                    Looper.prepare();
                    Toast.makeText(addRecord.this,"添加成功",Toast.LENGTH_SHORT).show();
                    Looper.loop();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }).start();
    }
}

  

能力达标分析功能实现:

package com.example.studyapplication;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.sql.SQLException;

public class updateSummary extends AppCompatActivity implements View.OnClickListener {

    private EditText ed_summary;
    private EditText ed_finish;
    private Button bt_update_summary;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_summary);
        ed_summary = findViewById(R.id.ed_summary);
        ed_finish = findViewById(R.id.ed_finish);
        bt_update_summary = findViewById(R.id.bt_update_summary);
        bt_update_summary.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String summary = ed_summary.getText().toString();
                String finish = ed_finish.getText().toString();
                Dao d =new Dao();
                SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE);
                String id = sharedPreferences.getString("id","");
                try {
                    d.updateSummary(summary,finish,id);
                    Looper.prepare();
                    Toast.makeText(updateSummary.this,"添加成功",Toast.LENGTH_SHORT).show();
                    Looper.loop();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }).start();
    }
}

  

posted @ 2024-03-26 17:42  umiQa  阅读(4)  评论(0编辑  收藏  举报