3.24

所花时间:2小时

代码量:63

博客篇:1

每日学习打卡功能实现

package com.example.studyapplication;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;
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 addTarget extends AppCompatActivity implements View.OnClickListener {

    private Button bt_add_target;
    private EditText ed_target;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_target);
        bt_add_target = findViewById(R.id.bt_add_target);
        ed_target = findViewById(R.id.ed_target);
        bt_add_target.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String target = ed_target.getText().toString();
                String id,name,unit;
                SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE);
                id = sharedPreferences.getString("id","");
                name = sharedPreferences.getString("name","");
                unit = sharedPreferences.getString("unit","");
                Summary s = new Summary();
                s.setId(id);
                s.setName(name);
                s.setUnit(unit);
                s.setTarget(target);
                s.setFinish("0");
                s.setSummary("0");
                Dao d =new Dao();
                try {
                    d.addTarget(s);
                    Looper.prepare();
                    Toast.makeText(addTarget.this,"添加成功",Toast.LENGTH_SHORT).show();
                    Looper.loop();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }).start();
    }
}

  

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