|
|
package com.example.myapplication;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
import android.app.AlertDialog;
|
|
|
import android.app.DatePickerDialog;
|
|
|
import android.content.ComponentName;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.widget.AdapterView;
|
|
|
import android.widget.ArrayAdapter;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.CheckBox;
|
|
|
import android.widget.EditText;
|
|
|
import android.widget.RadioGroup;
|
|
|
import android.widget.RatingBar;
|
|
|
import android.widget.Spinner;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
public class MainActivity2 extends Activity {
|
|
|
String firstPwd, secondPwd;
|
|
|
boolean isYes = true;
|
|
|
String userSex;
|
|
|
private EditText edtNewUserName;
|
|
|
private EditText edtPwd1, edtPwd2;
|
|
|
private EditText edtYear;
|
|
|
private RatingBar rtMarks;
|
|
|
private CheckBox cbRead, cbSing, cbComputer, cbSwing, cbGame, cbDancing, cbWuShu, cbRun;
|
|
|
private RadioGroup rdgGender;
|
|
|
private Spinner spnProvince, spnCity;
|
|
|
private Button btnReg, btnYear, back;
|
|
|
private List<String> cityList;
|
|
|
|
|
|
SqliteDbManager instance = SqliteDbManager.getInstance();
|
|
|
|
|
|
//JSONObject对象,处理一个一个的对象
|
|
|
//JSONObject对象,处理一个一个集合或者数组
|
|
|
//保存带集合的json字符串
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_main2);
|
|
|
initView();
|
|
|
btnReg.setOnClickListener(v -> {
|
|
|
if (!(cbDancing.isChecked() || cbRun.isChecked() || cbWuShu.isChecked() || cbGame.isChecked() || cbComputer.isChecked() || cbSing.isChecked() || cbSwing.isChecked() || cbRead.isChecked())) {
|
|
|
Toast.makeText(MainActivity2.this, "爱好必须选择一个", Toast.LENGTH_LONG).show();
|
|
|
isYes = false;
|
|
|
} else {
|
|
|
isYes = true;
|
|
|
}
|
|
|
|
|
|
if (!(edtPwd1.getText().toString().equals(edtPwd2.getText().toString()))) {
|
|
|
Toast.makeText(MainActivity2.this, "两次输入密码要一致", Toast.LENGTH_LONG).show();
|
|
|
isYes = false;
|
|
|
} else {
|
|
|
isYes = true;
|
|
|
}
|
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity2.this);
|
|
|
builder.setMessage("确认注册?");
|
|
|
builder.setPositiveButton("是", (dialog, which) -> {
|
|
|
|
|
|
Intent intent = new Intent(MainActivity2.this, MainActivity.class);
|
|
|
intent.putExtra("username", edtNewUserName.getText().toString());
|
|
|
intent.putExtra("password", edtPwd1.getText().toString());
|
|
|
this.register();
|
|
|
startActivity(intent);
|
|
|
});
|
|
|
builder.setNegativeButton("否", (dialog, which) -> isYes = false);
|
|
|
builder.create().show();
|
|
|
|
|
|
});
|
|
|
|
|
|
rdgGender.setOnCheckedChangeListener((group, checkedId) -> {
|
|
|
switch (checkedId) {
|
|
|
case R.id.rdMale:
|
|
|
Toast.makeText(MainActivity2.this, "男", Toast.LENGTH_LONG).show();
|
|
|
userSex = "男";
|
|
|
break;
|
|
|
case R.id.rdFemale:
|
|
|
Toast.makeText(MainActivity2.this, "女", Toast.LENGTH_LONG).show();
|
|
|
userSex = "女";
|
|
|
break;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
back.setOnClickListener(v -> {
|
|
|
Intent intent = new Intent();
|
|
|
ComponentName componentName = new ComponentName(MainActivity2.this, MainActivity.class);
|
|
|
intent.setComponent(componentName);
|
|
|
startActivity(intent);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private void register(){
|
|
|
String username = edtNewUserName.getText().toString();
|
|
|
String password = edtPwd1.getText().toString();
|
|
|
instance.insertTb("person", username, password);
|
|
|
}
|
|
|
void initView() {
|
|
|
instance.setSqliteDbOpen(this);
|
|
|
edtNewUserName = this.findViewById(R.id.edtNewUserName);
|
|
|
edtPwd1 = this.findViewById(R.id.edtPwd);
|
|
|
edtPwd2 = this.findViewById(R.id.edtSndPwd);
|
|
|
cbRead = this.findViewById(R.id.cbRead);
|
|
|
cbComputer = this.findViewById(R.id.cbCompute);
|
|
|
cbSing = this.findViewById(R.id.cbSing);
|
|
|
cbSwing = this.findViewById(R.id.cbSwing);
|
|
|
cbGame = this.findViewById(R.id.cbGame);
|
|
|
cbWuShu = this.findViewById(R.id.cbWushu);
|
|
|
cbRun = this.findViewById(R.id.cbRunning);
|
|
|
cbDancing = this.findViewById(R.id.cbDancing);
|
|
|
btnReg = this.findViewById(R.id.btnRegister);
|
|
|
rdgGender = this.findViewById(R.id.rdgGender);
|
|
|
back = this.findViewById(R.id.back);
|
|
|
isYes = true;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|