登录校验

package com.example.com.richang;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.textone)
    TextView textone;
    @BindView(R.id.edone)
    EditText edone;
    @BindView(R.id.edtwo)
    EditText edtwo;
    @BindView(R.id.btone)
    Button btone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        btone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (view.getId()){
                    case R.id.btone:
                        String username=edone.getText().toString().trim();
                        String password=edtwo.getText().toString().trim();

                        if(checkDate(username,password)){

                            login(username,password);

                        }
                    break;
                }
            }

            private void login(final String username, final String password) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Thread.sleep(2000);
                            if(username.equals("11")&&password.equals("11")){
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        textone.setText("登录成功!");
                                    }
                                });

                            }else{
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        textone.setText("登录失败!");
                                    }
                                });
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        });
    }


    private boolean checkDate(String username, String password) {
        if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
            return false;
        }
        return true;
    }

    ;


}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页