所花时间(包括上课): |
2h |
代码量(行): |
150左右 |
搏客量(篇): |
1 |
了解到的知识点: |
安卓 |
备注(其他): |
package com.example.app_02;
import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Calendar;
public class GoalActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener, View.OnClickListener {
private DatePicker dp_date;
private EditText ed_goal;
private SharedPreferences sharedPreferences;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_goal);
dp_date=findViewById(R.id.dp_date);
ed_goal=findViewById(R.id.ed_goal);
findViewById(R.id.btn_save).setOnClickListener(this);
// 获取日历的一个实例,里面包含了当前的年月日
Calendar calendar = Calendar.getInstance();
DatePickerDialog dialog = new DatePickerDialog(this, this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
// 显示日期对话框
dialog.show();
}
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {
sharedPreferences = getSharedPreferences("goal", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("goalDate", year + "-" + (month + 1) + "-" + dayOfMonth);
// editor.putString("goal", ed_goal.getText().toString());
editor.apply();
}
@Override
public void onClick(View view) {
sharedPreferences = getSharedPreferences("goal", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("goal", ed_goal.getText().toString());
editor.apply();
Intent intent = new Intent(this, FirstPageActivity.class);
startActivity(intent);
finish();
}
}
package com.example.app_02;标签:goal,19,ed,app,id,import,打卡,android From: https://www.cnblogs.com/pinganxile/p/18256700
import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.example.app_02.entity.UserInfo;
import com.example.app_02.utils.UserDao;
import com.example.app_02.utils.UserInfoDao;
public class InfoActivity extends AppCompatActivity implements View.OnClickListener {
private EditText ed_studentid;
private EditText ed_name;
private EditText ed_phonenumber;
private EditText ed_class;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);
ed_studentid = findViewById(R.id.ed_studentid);
ed_name = findViewById(R.id.ed_name);
ed_phonenumber = findViewById(R.id.ed_phonenumber);
ed_class = findViewById(R.id.ed_class);
findViewById(R.id.btn_sure).setOnClickListener(this);
}
@Override
public void onClick(View view) {
// 获取输入框的值
String studentid = ed_studentid.getText().toString();
String name = ed_name.getText().toString();
String phonenumber = ed_phonenumber.getText().toString();
String className = ed_class.getText().toString();
UserInfo userInfo = new UserInfo(studentid, name, phonenumber, className);
new Thread(new Runnable() {
@Override
public void run() {
UserInfoDao userInfoDao = new UserInfoDao();
userInfoDao.insertUserInfo(userInfo);
Bundle bundle1 = getIntent().getExtras();
if(bundle1 != null) {
String username = bundle1.getString("username", "");
UserDao userDao = new UserDao();
userDao.updateUserStudentid(userInfo, username);
}
// Toast.makeText(InfoActivity.this, "登记成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(InfoActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
}).start();
}
}