You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
6.7 KiB
171 lines
6.7 KiB
package com.demo.logining;
|
|
|
|
import androidx.annotation.IdRes;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
import android.widget.RadioGroup;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
|
|
import com.demo.logining.javabean.User;
|
|
import com.lljjcoder.style.citythreelist.CityBean;
|
|
import com.lljjcoder.style.citylist.utils.CityListLoader;
|
|
import com.lljjcoder.style.citythreelist.ProvinceActivity;
|
|
|
|
import java.util.Objects;
|
|
|
|
public class Register1Activity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener,
|
|
View.OnClickListener
|
|
{
|
|
private String acc="null";
|
|
private String password="";
|
|
private String rps ="";
|
|
private String sex = "男";
|
|
private String cityname="null";
|
|
|
|
private Button register1;
|
|
private EditText name1,password1,re_password;
|
|
private MySqliteOpenHelper mySqliteOpenHelper1;
|
|
|
|
private static final String print = "print";
|
|
|
|
static public boolean isRegister = false;
|
|
|
|
@SuppressLint("MissingInflatedId")
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.register);
|
|
name1 = findViewById(R.id.account);
|
|
password1 = findViewById(R.id.password);
|
|
re_password = findViewById(R.id.re_password);
|
|
register1 = findViewById(R.id.r_button);
|
|
mySqliteOpenHelper1 = new MySqliteOpenHelper(this);
|
|
|
|
//初始化组件
|
|
EditText Acc = findViewById(R.id.account); //账号
|
|
EditText Psw = findViewById(R.id.password); //密码
|
|
EditText Rps = findViewById(R.id.re_password); //确认密码
|
|
RadioGroup sex_group = findViewById(R.id.sex_group);
|
|
Button r_button = findViewById(R.id.r_button);
|
|
//添加监听事件
|
|
sex_group.setOnCheckedChangeListener(this);
|
|
register1.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
String n = name1.getText().toString();
|
|
Log.v(print,n);
|
|
String p = password1.getText().toString();
|
|
String re_p=re_password.getText().toString();
|
|
if(n.length()>=6&&n.length()<=11){
|
|
if(re_p.equals(p)){
|
|
if (re_p.length()>=6&&re_p.length()<=11){
|
|
User u = new User(n,p,sex,cityname);
|
|
long r = mySqliteOpenHelper1.register(u);
|
|
if(r != -1){
|
|
Toast.makeText(Register1Activity.this, "注册成功", Toast.LENGTH_SHORT).show();
|
|
Intent i = new Intent(Register1Activity.this,MainActivity.class);
|
|
startActivity(i);
|
|
}else {
|
|
Toast.makeText(Register1Activity.this, "注册失败", Toast.LENGTH_SHORT).show();
|
|
}
|
|
}
|
|
else{
|
|
Toast.makeText(Register1Activity.this, "密码格式错误", Toast.LENGTH_SHORT).show();
|
|
}
|
|
}
|
|
else{
|
|
Toast.makeText(Register1Activity.this, "两次密码输入不一致", Toast.LENGTH_SHORT).show();
|
|
}
|
|
}
|
|
else{
|
|
Toast.makeText(Register1Activity.this, "账号格式错误", Toast.LENGTH_SHORT).show();
|
|
}
|
|
}
|
|
});
|
|
|
|
// r_button.setOnClickListener(new View.OnClickListener() {
|
|
// @Override
|
|
// public void onClick(View view) {
|
|
// isRegister = true;
|
|
// acc=Acc.getText().toString();
|
|
// password=Psw.getText().toString();
|
|
// rps = Rps.getText().toString();
|
|
// switch (view.getId()) {
|
|
// case R.id.r_button:
|
|
// Bundle bundle=new Bundle();
|
|
// bundle.putString("acc",acc);
|
|
// bundle.putString("password",password);
|
|
// bundle.putString("rps", rps);
|
|
// bundle.putString("sex",sex);
|
|
// bundle.putString("city",cityname);
|
|
// Intent intent = new Intent(Register1Activity.this, MyInfor1Activity.class);
|
|
// intent.putExtras(bundle);
|
|
// if(Objects.equals(password, rps)) {
|
|
// Toast.makeText(Register1Activity.this, "注册成功!!!", Toast.LENGTH_LONG).show();
|
|
// startActivity(intent);
|
|
// }else
|
|
// Toast.makeText(Register1Activity.this, "两次密码不一致!", Toast.LENGTH_LONG).show();
|
|
// break; });
|
|
init();
|
|
}
|
|
|
|
public void init(){
|
|
//城市选择器,预加载器
|
|
CityListLoader.getInstance().loadProData(this);
|
|
//城市选择器的按钮监听事件
|
|
TextView spinner1 = (TextView) findViewById(R.id.cityPick);
|
|
spinner1.setOnClickListener(v -> {
|
|
Intent intent1 = new Intent(this, ProvinceActivity.class);
|
|
startActivityForResult(intent1, ProvinceActivity.RESULT_DATA);
|
|
});
|
|
}
|
|
|
|
@Override
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
if (requestCode == ProvinceActivity.RESULT_DATA) {
|
|
if (resultCode == RESULT_OK) {
|
|
if (data == null) {
|
|
return;
|
|
}
|
|
//省份结果
|
|
CityBean province = data.getParcelableExtra("province");
|
|
//城市结果
|
|
CityBean city = data.getParcelableExtra("city");
|
|
//区域结果
|
|
CityBean area = data.getParcelableExtra("area");
|
|
|
|
//显示/
|
|
String cityString = province.getName()+city.getName()+area.getName();
|
|
cityname=cityString;
|
|
TextView ctPk = (TextView) findViewById(R.id.cityPick);
|
|
ctPk.setText(cityname);
|
|
//Toast.makeText(this, cityString, Toast.LENGTH_SHORT).show();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
|
|
}
|
|
//传输性别
|
|
@Override
|
|
public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i){
|
|
if(i==R.id.rb_man){
|
|
sex="男";
|
|
}
|
|
else {
|
|
sex="女";
|
|
}
|
|
}
|
|
} |