public class RegisterActivity extends AppCompatActivity {
private String sex, infor;
@Override
protected void onCreate(Bundle saveInstanceState) {
super .onCreate(saveInstanceState);
setContentView(R.layout.activity_main2);
/**
*获取控件的id
**/
RadioGroup gender = (RadioGroup) findViewById(R.id.group);
final RadioButton male = (RadioButton) findViewById(R.id.radioButton);
final RadioButton female = (RadioButton) findViewById(R.id.radioButton2);
final Spinner spinner = (Spinner) findViewById(R.id.spinner);
final CheckBox c1 = (CheckBox) findViewById(R.id.checkBox);
final CheckBox c2 = (CheckBox) findViewById(R.id.checkBox2);
final CheckBox c3 = (CheckBox) findViewById(R.id.checkBox3);
final CheckBox c4 = (CheckBox) findViewById(R.id.checkBox4);
Button button1 = (Button) findViewById(R.id.but);
/**
* 获取checkbox里勾选的性别
**/
gender.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == male.getId()) {
sex = male.getText().toString();
} else {
sex = female.getText().toString();
}
}
});
/**
* 设置注册按钮的事件监听器,实现从注册界面到登录界面的跳转
**/
Button buttton1 = (Button) findViewById(R.id.but);
button1.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
/**
* 将checkbox里的选中的值赋给hobby
**/
String hobby = " " ;
if (c1.isChecked()) {
hobby += c1.getText().toString();
}
if (c2.isChecked()) {
hobby += c2.getText().toString();
}
if (c3.isChecked()) {
hobby += c3.getText().toString();
}
if (c4.isChecked()) {
hobby += c4.getText().toString();
}
/**
* 将Spinner里的值赋给spin,将所有的信息法如infor中
**/
String spin = spinner.getSelectedItem().toString();
String site1 = ((EditText) findViewById(R.id.username1)).getText().toString();
String site2 = ((EditText) findViewById(R.id.password1)).getText().toString();
String site3 = ((EditText) findViewById(R.id.password2)).getText().toString();
infor = "用户:" + site1 + "\n性别:" + sex + "\n学历:" + spin + "\n爱好:" + hobby;
/**
* 判断编辑框内容是否为空
**/
if (! "" .equals(site1) && ! "" .equals(site2) && ! "" .equals(site3)) {
Toast.makeText(Main2Activity. this , infor, Toast.LENGTH_LONG).show();
if (site2.equals(site3)) {
Intent intent = new Intent(RegisterActivity. this , MainActivity. class );
/**
* 将注册的信息打包,通过intent传给登录程序
**/
Bundle bundle = new Bundle();
bundle.putCharSequence( "site1" , site1);
bundle.putCharSequence( "site2" , site2);
bundle.putCharSequence( "site3" , site3);
bundle.putCharSequence( "infor" , infor);
intent.putExtras(bundle);
setResult( 0x11 , intent);
finish();
} else {
Toast.makeText(Main2Activity. this , "请确认密码一致" , Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(Main2Activity. this , "请将信息填写完整" , Toast.LENGTH_SHORT).show();
}
}
});
}
}
|
0评论