团队冲刺6

1.今天完成注册页面信息验证并提交到服务器

private Button button_zhuce;
private OkHttpClient okHttpClient=new OkHttpClient();
private Handler handler=new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
Intent intent = new Intent();
button_zhuce = (Button) findViewById(R.id.btn_register_button);
String panding= (String) msg.obj;
Log.e("sss",panding);
String zhuce="注册成功";
panding=panding.trim();
if(zhuce.equals(panding)){
Log.e("pp","1");
Toast.makeText(RegisterActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
button_zhuce.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

intent.setClass(RegisterActivity.this, MainActivity.class);//this前面为当前activty名称,class前面为要跳转到得activity名称
startActivity(intent);
}
});
}
else{
Log.e("pp","2");
Toast.makeText(RegisterActivity.this,panding,Toast.LENGTH_SHORT).show();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_tream);
initview();
}

private void initview() {
account=findViewById(R.id.register_name);
password=findViewById(R.id.register_password);
password_again=findViewById(R.id.register_password_agin);
email=findViewById(R.id.register_mail);
register=findViewById(R.id.btn_register_button);
register.setOnClickListener(this);
}

@Override
public void onClick(View v) {
if(password.getText().toString().equals(password_again.getText().toString())){
account2=account.getText().toString();
password2=password.getText().toString();
email2=email.getText().toString();
get();
}
else{
Toast.makeText(this,"密码不一致",Toast.LENGTH_SHORT).show();
}
}
private void get(){
new Thread(){
@Override
public void run() {
super.run();
String url="http://";
try {
String result=getData(url);
Log.e("内容:",result);
Message msg= Message.obtain();
msg.obj=result;
handler.sendMessage(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
private String getData(String url) throws IOException {
RequestBody responseBody=new FormBody.Builder()
.add("account",account2)
.add("password",password2)
.add("email",email2)
.build();
Request request=new Request.Builder().post(responseBody).url(url).build();
Response response=okHttpClient.newCall(request).execute();
return response.body().string();
}
posted @ 2021-05-06 21:31  chenghaixinag  阅读(94)  评论(0编辑  收藏  举报