01个人作业
项目介绍: 项目背景:石家庄铁道大学软件工程系从本学期开始要求21级学生每日打卡总结,特委托石家庄铁道大学给力21软件有限公司进行开发。
第一阶段目标: 1、用户注册:用户注册信息包括用户ID(学号)、用户名(姓名),手机号码,用户单位(班级),用户班级四项基本信息,用户第一次注册后,用户姓名不用每次输入 。 2、每日总结打卡:内容包括:日期、每日关键字、每日总结、坚持天数(自动计数,显示上次天数)、连续最长天数。 3、每日提醒记事本:设置每日事件闹钟,可以提醒用户每日必做事件。 4、当天数据存储到本地数据库,其余数据存储到远程服务器上。
第二阶段目标: 1、汇总统计:教师可以查询统计所有同学的每日打卡记录。 2、每日总结查询:可以按照关键字、每日总结查询。 3、自动从数据库中生成所有人的每日总结记录,包括序号、班级、学号、姓名、发表总次数。
手机APP使用说明书
一、 日记打卡app
1. 每日打卡app功能介绍
每日打卡app即安卓APP每日打卡系统,目前该APP版本1.0,安卓手机。用户可通过手机端APP实现随时随地的编辑打卡,闹钟提醒,查询已写打卡功能。
2. 每日打卡app的用户体系
为了方便用户使用每日打卡app,每日打卡app设置了用户体系,用户使用前需要先注册一个账号,为了避免用户忘记用户名和密码,本系统采用学号作为用户名进行注册,该系统可以记住密码以防用户忘记密码(指纹和手机密码可解锁)。
- 用户登录与注册
用户注册后,使用注册的用户名和密码进行登录;用户可以选择本机存储账号密码,以后启动该APP时就可以自动登录,注册登录界面如下:
- 添加打卡功能
每个用户可以根据需要添加每日需要的打卡日记,日记内容主要包括为五部分。
第一部分是你每日打卡的日期。
第二部分是用户每日打卡的关键字。
第三部分是用户对今日的总结,这些都会存储在手机端。
第四部分坚持天数。第五部分坚持最长时间。
5日记的查询功能
在该功能中,用户可以查询自己每天打卡的详细信息。
6闹钟提醒功能功能
源代码:
package com.example.clock.db;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.example.clock.jiben.DaKa;
import java.util.List;
public class Adapter extends BaseAdapter {
private Context context;
private List<DaKa> daKaList;
public Adapter(Context context,List<DaKa> list)
{
super();
this.context=context;
this.daKaList=list;
}
@Override
public int getCount() {
return daKaList.size();
}
@Override
public Object getItem(int i) {
return daKaList.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
return null;
}
}
package com.example.clock.db;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
import com.example.clock.jiben.User;
import com.example.clock.jiben.User;
import java.util.ArrayList;
import java.util.jar.Attributes;
import javax.xml.namespace.NamespaceContext;
public class DatabaseHelper extends SQLiteOpenHelper {
//创建一个数据库
private SQLiteDatabase db;
public DatabaseHelper(@Nullable Context context) {
super(context, "db_test", null, 1);
db = getReadableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
//在第一次创建数据库的时候,创建一些字段
String sql = "create table user(_id integer primary key autoincrement, name varchar(50), password varchar(40),names varchar(20),tel varchar(20),class varchar(20))";
db.execSQL(sql);//sql语句的执行函数
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//如果这个表中存在user,我们可以先把他去掉,然后重新创建
String sql = "DROP TABLE IF EXISTS user";
db.execSQL(sql);
onCreate(db);
}
//为使项目结构更加紧凑,我们在此类中编写增删改查的函数,因为只有登录和注册界面,因此只涉及到写入数据库insert和query的操作
public void insert(String name,String password ,String namele,String tel,String classs){
db.execSQL("insert into user(name,password,names,tel,class)VALUES(?,?,?,?,?)",new Object[]{name,password,namele,tel,classs});
}
public ArrayList<User> getAllDATA(){//查询数据库
ArrayList<User> list = new ArrayList<User>();
//查询数据库中的数据,并将这些数据按照降序的情况排列
Cursor cursor = db.query("user",null,null,null,null,null,"name DESC");
while(cursor.moveToNext()){
int index_name = cursor.getColumnIndex("name");
int index_password = cursor.getColumnIndex("password");
int index_names = cursor.getColumnIndex("names");
int index_tel = cursor.getColumnIndex("tel");
int index_classs=cursor.getColumnIndex("class");
String name = cursor.getString(index_name);
String password = cursor.getString(index_password);
String names = cursor.getString(index_names);
String tel = cursor.getString(index_tel);
String classs = cursor.getString(index_classs);
list.add(new User(name,password,names,tel,classs));
}
return list;
}
}
package com.example.clock.db;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.hardware.biometrics.BiometricManager;
import android.view.contentcapture.DataRemovalRequest;
import androidx.annotation.Nullable;
import com.example.clock.jiben.DaKa;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.jar.Attributes;
import javax.xml.namespace.NamespaceContext;
public class DbHelper extends SQLiteOpenHelper {
//创建一个数据库
private static SQLiteDatabase db;
public DbHelper(@Nullable Context context) {
super(context, "dbs_test", null, 1);
db = getReadableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
//在第一次创建数据库的时候,创建一些字段
String sql = "create table daka(_id integer, date varchar(50), keyword varchar(40),zj varchar(20),jc varchar(20),max varchar(20))";
db.execSQL(sql);//sql语句的执行函数
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//如果这个表中存在user,我们可以先把他去掉,然后重新创建
String sql = "DROP TABLE IF EXISTS daka";
db.execSQL(sql);
onCreate(db);
}
//为使项目结构更加紧凑,我们在此类中编写增删改查的函数,因为只有登录和注册界面,因此只涉及到写入数据库insert和query的操作
public void insert(String date,String keyword ,String zj,String jc,String max){
db.execSQL("insert into daka(date,keyword,zj,jc,max)VALUES(?,?,?,?,?)",new Object[]{date,keyword,zj,jc,max});
}
public ArrayList<DaKa> getAllDATA(){//查询数据库
ArrayList<DaKa> list = new ArrayList<DaKa>();
//查询数据库中的数据,并将这些数据按照降序的情况排列
Cursor cursor = db.query("daka",null,null,null,null,null,"max DESC");
while(cursor.moveToNext()){
int index_date = cursor.getColumnIndex("date");
int index_keyword = cursor.getColumnIndex("keyword");
int index_zj = cursor.getColumnIndex("zj");
int index_jc = cursor.getColumnIndex("jc");
int index_max=cursor.getColumnIndex("max");
String date = cursor.getString(index_date);
String key = cursor.getString(index_keyword);
String zjs = cursor.getString(index_zj);
String jcs = cursor.getString(index_jc);
String maxx = cursor.getString(index_max);
list.add(new DaKa(date,key,zjs,jcs,maxx));
}
return list;
}
/* public List<Map<String,String>> getcx(){//查询数据库
List<Map<String,String>> list = new ArrayList<Map<String,String>>();
//查询数据库中的数据,并将这些数据按照降序的情况排列
int i=0;
Cursor cursor = db.query("daka",null,null,null,null,null,null);
if(cursor!=null&&cursor.getCount()==1){
while(cursor.moveToNext()){
int index_date = cursor.getColumnIndex("date");
int index_keyword = cursor.getColumnIndex("keyword");
int index_zj = cursor.getColumnIndex("zj");
int index_jc = cursor.getColumnIndex("jc");
int index_max=cursor.getColumnIndex("max");
String date = cursor.getString(index_date);
String key = cursor.getString(index_keyword);
String zjs = cursor.getString(index_zj);
String jcs = cursor.getString(index_jc);
String maxx = cursor.getString(index_max);
Map<String,String> data=new HashMap<String,String>();
data.put("date", date);
data.put("key",key);
list.add(data);
i++;
}
}
/*while(cursor.moveToNext()){
int index_date = cursor.getColumnIndex("date");
int index_keyword = cursor.getColumnIndex("keyword");
int index_zj = cursor.getColumnIndex("zj");
int index_jc = cursor.getColumnIndex("jc");
int index_max=cursor.getColumnIndex("max");
String date = cursor.getString(index_date);
String key = cursor.getString(index_keyword);
String zjs = cursor.getString(index_zj);
String jcs = cursor.getString(index_jc);
String maxx = cursor.getString(index_max);
list.add(new DaKa(date,key,zjs,jcs,maxx));
}
return list;
}*/
}
package com.example.clock.db;
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
import com.example.clock.MainActivity;
import com.example.clock.jiben.DaKa;
import java.util.ArrayList;
import java.util.List;
public class Help extends SQLiteOpenHelper {
public Help(Context context) {
super(context, "dbs_test", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "create table daka(_id integer, date varchar(50), keyword varchar(40),zj varchar(20),jc varchar(20),max varchar(20))";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
package com.example.clock.jiben;
public class DaKa {
private int id;
private String date;
private String keyword;
private String zj;
private String jc;
private String max;
public DaKa() {
}
public DaKa(String date, String keyword, String zj, String jc, String max) {
this.date = date;
this.keyword = keyword;
this.zj = zj;
this.jc = jc;
this.max = max;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
public String getZj() {
return zj;
}
public void setZj(String zj) {
this.zj = zj;
}
public String getJc() {
return jc;
}
public void setJc(String jc) {
this.jc = jc;
}
public String getMax() {
return max;
}
public void setMax(String max) {
this.max = max;
}
@Override
public String toString() {
return "DaKa{" +
"id=" + id +
", date='" + date + '\'' +
", keyword='" + keyword + '\'' +
", zj='" + zj + '\'' +
", jc='" + jc + '\'' +
", max='" + max + '\'' +
'}';
}
}
package com.example.clock.jiben;
public class User {
private int id;
private String name;
private String password;
private String names;
private String tel;
private String classs;
public User(String name, String password, String names, String tel, String classs) {
this.name = name;
this.password = password;
this.names = names;
this.tel = tel;
this.classs = classs;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getNames() {
return names;
}
public void setNames(String names) {
this.names = names;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getClasss() {
return classs;
}
public void setClasss(String classs) {
this.classs = classs;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", password='" + password + '\'' +
", names='" + names + '\'' +
", tel='" + tel + '\'' +
", classs='" + classs + '\'' +
'}';
}
}
package com.example.clock;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//Log.e("clock","1");
Toast.makeText(context, "闹铃响了, 记得进行每日总结打卡!!!", Toast.LENGTH_LONG).show();
}
}
package com.example.clock;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.clock.db.DatabaseHelper;
import com.example.clock.jiben.User;
import com.example.clock.jiben.User;
import java.util.ArrayList;
public class Login extends AppCompatActivity {
private DatabaseHelper mSQLite;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button btn_login = findViewById(R.id.login);
Button btn_register = findViewById(R.id.register);
EditText ed_name = findViewById(R.id.userName);
EditText ed_password = findViewById(R.id.userpassword);
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = ed_name.getText().toString().trim();
String password = ed_password.getText().toString().trim();
ArrayList<User> data = mSQLite.getAllDATA();
boolean flag = false;
for(int i = 0; i < data.size(); i++){
User userdata = data.get(i);
if(name.equals(userdata.getName())&&password.equals(userdata.getPassword())){
flag = true;
break;
}else{
flag = false;
}
}
if(!TextUtils.isEmpty(name)&&!TextUtils.isEmpty(password)){
if(flag){
Intent intent1 = new Intent(Login.this, MainActivity.class);
startActivity(intent1);
finish();
Toast.makeText(Login.this, "登录成功", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Login.this, "用户名或密码不正确", Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(Login.this, "用户名与密码不能为空", Toast.LENGTH_SHORT).show();
}
}
});
btn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent2 = new Intent(Login.this, Register.class);
startActivity(intent2);
finish();
}
});
mSQLite = new DatabaseHelper(Login.this);
}
}
package com.example.clock;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import java.util.Calendar;
import java.util.TimeZone;
public class MainActivity extends AppCompatActivity {
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioButton rbYes = findViewById(R.id.rb_yes);
RadioButton rbNo = findViewById(R.id.rb_no);
rbYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText ed_hour = findViewById(R.id.hour);
EditText ed_mins= findViewById(R.id.min);
int s1= Integer.parseInt(ed_hour.getText().toString());
int s2= Integer.parseInt(ed_mins.getText().toString());
startRemind(s1,s2);
}
});
rbNo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
stopRemind();
}
});
}
/**
* 开启提醒
* @param a
* @param b
*/
private void startRemind(int a, int b){
//得到日历实例,主要是为了下面的获取时间
Calendar mCalendar = Calendar.getInstance();
mCalendar.setTimeInMillis(System.currentTimeMillis());
//获取当前毫秒值
long systemTime = System.currentTimeMillis();
//是设置日历的时间,主要是让日历的年月日和当前同步
mCalendar.setTimeInMillis(System.currentTimeMillis());
// 这里时区需要设置一下,不然可能个别手机会有8个小时的时间差
mCalendar.setTimeZone(TimeZone.getTimeZone("GMT+8"));
//设置在几点提醒 设置的为点
mCalendar.set(Calendar.HOUR_OF_DAY, a);
//设置在几分提醒 设置的为分
mCalendar.set(Calendar.MINUTE, b);
//下面这两个看字面意思也知道
mCalendar.set(Calendar.SECOND, 0);
mCalendar.set(Calendar.MILLISECOND, 0);
//上面设置的就是13点25分的时间点
//获取上面设置的13点25分的毫秒值
long selectTime = mCalendar.getTimeInMillis();
// 如果当前时间大于设置的时间,那么就从第二天的设定时间开始
if(systemTime > selectTime) {
mCalendar.add(Calendar.DAY_OF_MONTH, 1);
}
//AlarmReceiver.class为广播接受者
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0);
//得到AlarmManager实例
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
//**********注意!!下面的两个根据实际需求任选其一即可*********
/**
* 单次提醒
* mCalendar.getTimeInMillis() 上面设置的13点25分的时间点毫秒值
*/
am.set(AlarmManager.RTC_WAKEUP, mCalendar.getTimeInMillis(), pi);
/**
* 重复提醒
* 第一个参数是警报类型;下面有介绍
* 第二个参数网上说法不一,很多都是说的是延迟多少毫秒执行这个闹钟,但是我用的刷了MIUI的三星手机的实际效果是与单次提醒的参数一样,即设置的13点25分的时间点毫秒值
* 第三个参数是重复周期,也就是下次提醒的间隔 毫秒值 我这里是一天后提醒
*/
am.setRepeating(AlarmManager.RTC_WAKEUP, mCalendar.getTimeInMillis(), (1000 * 60 ), pi);
}
/**
* 关闭提醒
*/
private void stopRemind(){
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0,
intent, 0);
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
//取消警报
am.cancel(pi);
Toast.makeText(this, "关闭了提醒", Toast.LENGTH_SHORT).show();
}
public void onClick (View view){
switch (view.getId()) {
case R.id.main_iv_search:
break;
case R.id.main_btn_edit:
Intent intent=new Intent(this,RecordFrg.class);//跳转界面的操作
startActivity(intent);
break;
case R.id.main_button_more:
Intent intent1=new Intent(this,Seesome.class);
startActivity(intent1);
break;
}
}
}
/* public void onClick (View view){
switch (view.getId()) {
case R.id.main_iv_search:
break;
case R.id.main_btn_edit:
Intent intent=new Intent(this,RecordFrg.class);//跳转界面的操作
startActivity(intent);
break;
case R.id.main_button_more:
Intent intent1=new Intent(this,Seesome.class);
startActivity(intent1);
break;
}
}
package com.example.clock;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.icu.text.SimpleDateFormat;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.clock.db.DatabaseHelper;
import com.example.clock.db.DbHelper;
import com.example.clock.jiben.DaKa;
import com.example.clock.jiben.User;
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.Date;
public class RecordFrg extends AppCompatActivity {
private DbHelper mSQLite;
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_record_frg);
//找到各个控件
Button btn_ready = findViewById(R.id.redays);
Button btn_back = findViewById(R.id.backs);
TextView dates = findViewById(R.id.timeET);
EditText ed_Key = findViewById(R.id.key_word);
EditText ed_zongjie = findViewById(R.id.zongjie);
EditText ed_jianchi= findViewById(R.id.jianchi);
EditText ed_max = findViewById(R.id.max_day);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
dates.setText(simpleDateFormat.format(date));
//注册监听事件
btn_ready.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//获取输入的用户名和密码
String datess = dates.getText().toString().trim();
String keyword = ed_Key.getText().toString().trim();
String zj =ed_zongjie.getText().toString().trim();
String jc = ed_jianchi.getText().toString().trim();
String max=ed_max.getText().toString().trim();
//获取数据库数据,判断用户名是否已存在
/* ArrayList<DaKa> data = mSQLite.getAllDATA();
boolean flag = false;
for(int i = 0; i < data.size(); i++){
DaKa userdata = data.get(i);
if(.equals(userdata.getName())){
flag = true;
break;
}else{
flag = false;
}
}*/
//判断用户名和密码是否为空
if(!TextUtils.isEmpty(datess)&&!TextUtils.isEmpty(keyword)){
mSQLite.insert(datess, keyword,zj,jc,max);
Intent intent1 = new Intent(RecordFrg.this, MainActivity.class);
startActivity(intent1);
finish();
Toast.makeText(RecordFrg.this, "打卡成功", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(RecordFrg.this, "内容不可以为空", Toast.LENGTH_SHORT).show();
}
}
});
//监听返回按钮
btn_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent2 = new Intent(RecordFrg.this, MainActivity.class);
startActivity(intent2);
finish();
}
});
mSQLite = new DbHelper(RecordFrg.this);
}
}*/
package com.example.clock;
import static com.example.clock.R.id.userNames;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.clock.db.DatabaseHelper;
import com.example.clock.jiben.User;
import com.example.clock.jiben.User;
import java.util.ArrayList;
public class Register extends AppCompatActivity {
private DatabaseHelper mSQLite;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
//找到各个控件
Button btn_ready = findViewById(R.id.reday);
Button btn_back = findViewById(R.id.back);
EditText ed_name = findViewById(R.id.userName);
EditText ed_password = findViewById(R.id.userpassword);
EditText ed_name1 = findViewById(R.id.userNames);
EditText ed_tel= findViewById(R.id.usertel);
EditText ed_class = findViewById(R.id.userclass);
//注册监听事件
btn_ready.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//获取输入的用户名和密码
String name = ed_name.getText().toString().trim();
String password = ed_password.getText().toString().trim();
String name1 =ed_name1.getText().toString().trim();
String tel = ed_tel.getText().toString().trim();
String classs=ed_class.getText().toString().trim();
//获取数据库数据,判断用户名是否已存在
ArrayList<User> data = mSQLite.getAllDATA();
boolean flag = false;
for(int i = 0; i < data.size(); i++){
User userdata = data.get(i);
if(name.equals(userdata.getName())){
flag = true;
break;
}else{
flag = false;
}
}
//判断用户名和密码是否为空
if(!TextUtils.isEmpty(name)&&!TextUtils.isEmpty(password)){
if(!flag){
mSQLite.insert(name, password,name1,tel,classs);
Intent intent1 = new Intent(Register.this, Login.class);
startActivity(intent1);
finish();
Toast.makeText(Register.this, "注册成功", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Register.this, "用户名已被注册", Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(Register.this, "用户名与密码不能为空", Toast.LENGTH_SHORT).show();
}
}
});
//监听返回按钮
btn_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent2 = new Intent(Register.this, Login.class);
startActivity(intent2);
finish();
}
});
mSQLite = new DatabaseHelper(Register.this);
}
package com.example.clock;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cursoradapter.widget.SimpleCursorAdapter;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.example.clock.db.Help;
public class Seesome extends AppCompatActivity {
private SimpleCursorAdapter mAdapter;
private ListView listView;
private Button btn_add;
private Button btn_delete;
private Button btn_back;
private EditText et_date;
private EditText et_gj;
private EditText et_zj;
private EditText et_jc;
private EditText et_max;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seesome);
btn_add = (Button) findViewById(R.id.btn_add);
btn_delete = (Button) findViewById(R.id.btn_delete);
listView = (ListView) findViewById(R.id.list);
btn_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//ad1dData();
refleshListView();
}
});
btn_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteData();
refleshListView();
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Toast.makeText(MainActivity.this,""+position,Toast.LENGTH_SHORT).show();
int positions = position + 1;
Help db = new Help(Seesome.this);
SQLiteDatabase dbWrite = db.getWritableDatabase();
dbWrite.delete("daka","_id=?",new String[]{""+positions});
dbWrite.close();
refleshListView();
}
});
}
public void addData() {
btn_back = (Button) findViewById(R.id.btn_back);
et_date = (EditText) findViewById(R.id.timeET);
et_gj = (EditText) findViewById(R.id.key_word);
et_zj = (EditText) findViewById(R.id.zongjie);
et_jc = (EditText) findViewById(R.id.jianchi);
et_max = (EditText) findViewById(R.id.max_day);
btn_add = (Button) findViewById(R.id.btn_add);
btn_delete = (Button) findViewById(R.id.btn_delete);
listView = (ListView) findViewById(R.id.list);
btn_add.setVisibility(View.GONE);
btn_delete.setVisibility(View.GONE);
listView.setVisibility(View.GONE);
btn_back.setVisibility(View.VISIBLE);
et_date.setVisibility(View.VISIBLE);
et_gj.setVisibility(View.VISIBLE);
et_zj.setVisibility(View.VISIBLE);
et_jc.setVisibility(View.VISIBLE);
et_max.setVisibility(View.VISIBLE);
btn_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btn_add.setVisibility(View.VISIBLE);
btn_delete.setVisibility(View.VISIBLE);
listView.setVisibility(View.VISIBLE);
btn_back.setVisibility(View.GONE);
et_date.setVisibility(View.GONE);
et_gj.setVisibility(View.GONE);
et_zj.setVisibility(View.GONE);
et_jc.setVisibility(View.GONE);
et_max.setVisibility(View.GONE);
String date = et_date.getText().toString(),
keyw =et_gj.getText().toString(),
zj = et_zj.getText().toString(),
max = et_max.getText().toString(),
jc =et_jc.getText().toString();
Help db = new Help(Seesome.this);
SQLiteDatabase dbWrite = db.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("date", date);
cv.put("keyword", keyw);
cv.put("zj",zj );
cv.put("jc",jc );
cv.put("max",max );
dbWrite.insert("daka", null, cv);
dbWrite.close();
refleshListView();
}
});
// String id = et_id.getText().toString(),
// name =et_name.getText().toString(),
// sex = et_sex.getText().toString();
//
//
// Db db = new Db(MainActivity.this);
// SQLiteDatabase dbWrite = db.getWritableDatabase();
//
// ContentValues cv = new ContentValues();
// cv.put("_id",id);
// cv.put("name", name);
// cv.put("sex", sex);
// dbWrite.insert("user2", null, cv);
//
// dbWrite.close();
}
public void deleteData() {
Help db = new Help(Seesome.this);
SQLiteDatabase dbWrite = db.getWritableDatabase();
dbWrite.delete("daka",null,new String[]{});
dbWrite.close();
}
public void refleshListView() {
Help db = new Help(Seesome.this);
SQLiteDatabase dbRead = db.getReadableDatabase();
Cursor c = dbRead.query("daka", null, null, null, null, null, null);
mAdapter = new SimpleCursorAdapter(Seesome.this, R.layout.fragment_one_item, c,
new String[]{"date","keyword"}, new int[]{R.id.tv_expense_date,R.id.tv_expense_gj});
listView.setAdapter(mAdapter);
dbRead.close();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/img_3"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登录和注册"
android:textSize="26sp"
android:gravity="center"/>
<LinearLayout
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="用户名:"
android:layout_marginTop="30dp"
android:textSize="25sp"
android:textColor="#000000"
android:layout_weight="1"/>
<EditText
android:id="@+id/userName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="请输入用户名"
android:layout_marginTop="30dp"
android:textSize="20sp"
android:textColor="#2196F3"
android:layout_weight="2"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="密码:"
android:textSize="25sp"
android:layout_marginTop="30dp"
android:textColor="#000000"
android:layout_weight="1"/>
<EditText
android:id="@+id/userpassword"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="请输入密码"
android:textSize="20sp"
android:textColor="#2196F3"
android:layout_weight="2"
android:inputType="textWebPassword"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登录"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="30dp"
android:textSize="25sp"
android:onClick="onclick"/>
<Button
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="30dp"
android:textSize="25sp"
android:textColor="#FFFFFF"
android:textAllCaps="false"
android:text="注册"
android:id="@+id/register"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>