在今天一整天再弄android stuido 的这个app 很难,自己在网上查找相关代码,对于记事本的增加,删除,连接数据库等等,每个界面都要相互关联。
package com.example.qwe; /* * 注册界面 * */ import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.content.Intent; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.Toast; import com.example.qwe.db.DatabaseHelper; import com.example.qwe.Bean.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.bt_registeractivity_register); ImageView btn_back = findViewById(R.id.iv_registeractivity_back); EditText ed_name = findViewById(R.id.et_registeractivity_id); EditText ed_password = findViewById(R.id.et_registeractivity_password); EditText ed_name1 = findViewById(R.id.et_registeractivity_username); EditText ed_tel = findViewById(R.id.et_registeractivity_phone); EditText ed_class = findViewById(R.id.et_registeractivity_classes); //注册监听事件 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.getId())) { 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); } }
标签:总结,Toast,ed,每日,Register,import,android,id From: https://www.cnblogs.com/nanbei666/p/17181312.html