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.

145 lines
5.6 KiB

package com.example.test.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.example.test.R;
import com.lljjcoder.Interface.OnCityItemClickListener;
import com.lljjcoder.bean.CityBean;
import com.lljjcoder.bean.DistrictBean;
import com.lljjcoder.bean.ProvinceBean;
import com.lljjcoder.citywheel.CityConfig;
import com.lljjcoder.style.citypickerview.CityPickerView;
public class register extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
private EditText userEdit;
private EditText passEdit;
private EditText paEdit;
private RadioGroup sexBut;
private TextView adressText;
private String sex ="男";
private Button regBut;
CityPickerView citypv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
init();
}
public void init(){
citypv = new CityPickerView();
citypv.init(this);
initConfig();
citypv.setOnCityItemClickListener(new OnCityItemClickListener() {
@Override
public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
String pro = province.getName();
String ci = city.getName();
String dis = district.getName();
adressText.setText(String.format("%s %s %s",pro,ci,dis));
}
@Override
public void onCancel() {
}
});
userEdit = findViewById(R.id.reg_username);
passEdit = findViewById(R.id.reg_password);
paEdit = findViewById(R.id.reg_apassword);
adressText = findViewById(R.id.reg_adress);
adressText.setOnClickListener(this);
sexBut = findViewById(R.id.reg_sex);
sexBut.setOnCheckedChangeListener(this);
regBut = findViewById(R.id.reg_register);
regBut.setOnClickListener(this);
}
private void initConfig() {
CityConfig cityConfig = new CityConfig.Builder()
.title("选择城市")//标题
.titleTextSize(18)//标题文字大小
.titleTextColor("#585858")//标题文字颜 色
.titleBackgroundColor("#E9E9E9")//标题栏背景色
.confirTextColor("#585858")//确认按钮文字颜色
.confirmText("ok")//确认按钮文字
.confirmTextSize(16)//确认按钮文字大小
.cancelTextColor("#585858")//取消按钮文字颜色
.cancelText("cancel")//取消按钮文字
.cancelTextSize(16)//取消按钮文字大小
.setCityWheelType(CityConfig.WheelType.PRO_CITY_DIS)//显示类,只显示省份一级,显示省市两级还是显示省市区三级
.showBackground(true)//是否显示半透明背景
.visibleItemsCount(7)//显示item的数量
.province("浙江省")//默认显示的省份
.city("杭州市")//默认显示省份下面的城市
.district("滨江区")//默认显示省市下面的区县数据
.provinceCyclic(true)//省份滚轮是否可以循环滚动
.cityCyclic(true)//城市滚轮是否可以循环滚动
.districtCyclic(true)//区县滚轮是否循环滚动
.drawShadows(false)//滚轮不显示模糊效果
.setLineColor("#03a9f4")//中间横线的颜色
.setLineHeigh(5)//中间横线的高度
.setShowGAT(true)//是否显示港澳台数据,默认不显示
.build();
citypv.setConfig(cityConfig);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.reg_adress:
citypv.showCityPicker();
break;
case R.id.reg_register:
check();
break;
}
}
private void check() {
Intent intent = new Intent(this,login.class);
String username = userEdit.getText().toString();
String password = passEdit.getText().toString();
String apassword = paEdit.getText().toString();
String adress = adressText.getText().toString();
if(password.equals(apassword)){
if(username.equals("")||username.startsWith(" ")||password.equals("")||password.startsWith(" ")){
Toast.makeText(this,"用户名或密码为空",Toast.LENGTH_SHORT).show();
}else {
if(adress.equals("")||adress.equals("地址选择"))
Toast.makeText(this,"未选择地址",Toast.LENGTH_SHORT).show();
else{
Bundle bundle = new Bundle();
bundle.putString("username",username);
bundle.putString("password",password);
bundle.putString("adress",adress);
bundle.putString("sex",sex);
intent.putExtras(bundle);
startActivity(intent);
}
}
}
else {
Toast.makeText(this,"两次密码不一致",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//根据用户选择来改变sex的值
sex = R.id.reg_male==checkedId?"男":"女";
}
}