布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.bwie.lizhi.lianxi_login_resgin.activity.ResignActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:gravity="center"
android:padding="10dp"
android:text="注册" />
<EditText
android:id="@+id/tell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入手机号" />
<EditText
android:id="@+id/pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:onClick="saved"
android:text="立即注册" />
</LinearLayout>
ResignActivity
public class ResignActivity extends AppCompatActivity implements IResign{
private EditText tell;
private EditText pass;
private String phoneNum;
private String passNum;
private ResignPresenter resignPresenter;
private String regex = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resign);
initView();
}
private void initView() {
tell = (EditText) findViewById(R.id.tell);
pass = (EditText) findViewById(R.id.pass);
resignPresenter = new ResignPresenter(this);
}
public void saved(View view) {
phoneNum = tell.getText().toString();
passNum = pass.getText().toString();
if(!TextUtils.isEmpty(phoneNum)&&!TextUtils.isEmpty(passNum)){
Pattern p = Pattern.compile(regex);
Matcher matcher = p.matcher(phoneNum);
if(matcher.matches()&&passNum.length()>=6){
resignPresenter.sendData(Urls.ZhuCeUrl,phoneNum,passNum);
}else if(!matcher.matches()){
Toast.makeText(ResignActivity.this,"手机号有误",Toast.LENGTH_SHORT).show();
}else if(passNum.length()<6){
Toast.makeText(ResignActivity.this,"密码长度有有误",Toast.LENGTH_SHORT).show();
}
}else if(TextUtils.isEmpty(phoneNum)){
Toast.makeText(ResignActivity.this,"手机号不能为空",Toast.LENGTH_SHORT).show();
}else if(TextUtils.isEmpty(passNum)){
Toast.makeText(ResignActivity.this,"密码不能为空",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onSuccessRes(final Zhuce_Bean bean) {
runOnUiThread(new Runnable() {
@Override
public void run() {
String code = bean.getCode();
if("0".equals(code)){
Toast.makeText(ResignActivity.this,bean.getMsg(),Toast.LENGTH_SHORT).show();
ResignActivity.this.finish();
}else{
Toast.makeText(ResignActivity.this,bean.getMsg(),Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onFaildRes(String s) {
Log.e("Tag", "onFaildRes: "+s );
}
}