所花时间: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(); } }
标签:target,androidx,add,3.24,import,android,id From: https://www.cnblogs.com/chukjbgg333/p/18092705