个人作业——app
本次个人作业老师让我们完成一个定时打卡app可以实现自动读取当前时间存入数据库,并且实现注册登录,
线面是一些对应的文件:
MainActivity。java
主界面 `package com.example.conect_sqlite;import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.example.conect_sqlite.util.ToastUtil;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
//声明控件
private Button mBtnlogin ;
public EditText mEtuser;
public EditText mEtpassword;
private MySQLiteOpenHelper mMySQLiteOpenHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//找到控件
mBtnlogin = findViewById(R.id.btn_login);
mEtuser=findViewById(R.id.et_1);
mEtpassword=findViewById(R.id.et_2);
mMySQLiteOpenHelper =new MySQLiteOpenHelper(this);
//实现直接跳转
/* mBtnlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent =null;
intent =new Intent(MainActivity.this,function.class);
startActivity(intent);
}
});*/
//匹配对应用户名密码才操作
mBtnlogin.setOnClickListener(this);
}
@Override
public void onPointerCaptureChanged(boolean hasCapture) {
}
@Override
public void onClick(View view ) {
String uid=mEtuser.getText().toString();
String password=mEtpassword.getText().toString();
//从数据库中删除
int row=mMySQLiteOpenHelper.searchuid(uid,password);
if(row==1){
ToastUtil.toastLong(this,"登录成功!");
Intent intent=null;//这里必须声明为空然后跳转
intent=new Intent(MainActivity.this,function.class);
intent.putExtra("password",password);//将这个页面的数据传入到下一个页面
startActivity(intent);
}else{
ToastUtil.toastLong(this,"登录失败!用户名或密码错误!");
}
/* Intent intent=null;
//名称正确进行跳转;
if(username.equals("wqy")&&password.equals("123456"))
{
intent=new Intent(MainActivity.this,function.class);
startActivity(intent);
}else//失败弹出弹窗
{
}*/
}
public void zhuce(View view) {
Intent intent =new Intent(MainActivity.this,zhuce.class);//进行跳转
startActivity(intent);
}
}`
这里是function页面用于功能选择的
function.java
`package com.example.conect_sqlite;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class function extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_function);
}
public void insertDate(View view) {
Intent intent=null;
intent=this.getIntent();
String password=intent.getStringExtra("password");
//从上一个页面或取账号数据
intent =new Intent(function.this,add.class);//进行跳转
intent.putExtra("password", password);
//将这个页面的数据传入到下一个页面
startActivity(intent);
}
public void deleteDate(View view) {
Intent intent =new Intent(function.this,delete.class);//进行跳转
startActivity(intent);
}
public void updateDate(View view) {
Intent intent=null;
intent=this.getIntent();
String password=intent.getStringExtra("password");
intent=new Intent(function.this,updata.class);
intent.putExtra("password", password);
startActivity(intent);
}
public void searchDate(View view) {
Intent intent=null;
intent=new Intent(function.this,list.class);
startActivity(intent);
}
}add界面用于添加打卡数据
package com.example.conect_sqlite;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.conect_sqlite.bean.student;
import java.text.SimpleDateFormat;
import java.util.Date;
public class add extends AppCompatActivity {
private EditText etname,etthing,etdate;
private MySQLiteOpenHelper mMySQLiteOpenHelper;
//名字 事件 提醒日期
//保存
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
//控件初始化
initView();
mMySQLiteOpenHelper =new MySQLiteOpenHelper(this);
}
private void initView() {
etname =findViewById(R.id.et_name);
etthing=findViewById(R.id.et_thing);
etdate=findViewById(R.id.et_date);
}
public void insertDate(View view) {
Intent intent=null;
intent=this.getIntent();
String password=intent.getStringExtra("password");//从上一个页面或取账号数据
String name= etname.getText().toString().trim();
String thing= etthing.getText().toString().trim();
String date= etdate.getText().toString().trim();
student student1=new student();
student1.setPassword(password);
student1.setName(name);
student1.setThing(thing);
student1.setDate(date);
student1.setDaytime(getCurrentTimeFormat());
long rowId=mMySQLiteOpenHelper.insertData1(student1);
if(rowId!=-1){
Toast.makeText(this,"打卡成功!",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(this,"打卡失败!",Toast.LENGTH_SHORT).show();
}
}
private String getCurrentTimeFormat(){//创建我们的实时获取时间。
SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyy年MM月dd HH:mm:ss");
Date date = new Date();
return simpleDateFormat.format(date);
}
//插入数据库中
}`