wuhudamahua
wuhudamahua
采纳率27.3%
2016-04-19 11:19 阅读 1.7k

Android应用设置密码登录错误

package com.example.broadbestpractice;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends BaseActivity{

private EditText accountEdit;
private EditText passwordEdit;
private Button login;
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.id.login);
    accountEdit=(EditText) findViewById(R.id.account);
    passwordEdit=(EditText) findViewById(R.id.password);
    login=(Button) findViewById(R.id.login);
    login.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            String account=accountEdit.getText().toString();
            String password=passwordEdit.getText().toString();
            if(account.equals("admin")&&password.equals("123456"))
            {
                Intent intent=new Intent(LoginActivity.this,MainActivity.class);
                startActivity(intent);
                finish();
            }
            else
            {
                Toast.makeText(LoginActivity.this, "error", 1).show();
            }
        }
    });
}

}

我输入正确的账号和密码总是弹出taost说error

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • rvncds rvncds 2016-04-19 11:30

    String account=accountEdit.getText().toString();
    String password=passwordEdit.getText().toString();
    if(account != null){
    account = account.trim();
    }
    if(password != null ){
    password = password.trim();
    }
    if(account.equals("admin")&&password.equals("123456"))
    {
    Intent intent=new Intent(LoginActivity.this,MainActivity.class);
    startActivity(intent);
    finish();
    }else{
    Toast.makeText(LoginActivity.this, "error", 1).show();
    Log.i("","account:"+account+",password:"+password);
    }

    点赞 评论 复制链接分享
  • lxk_1993 103style 2016-04-20 01:01

    if(account.trim().equals("admin")&&password.trim().equals("123456"))
    换成这样试试

    点赞 评论 复制链接分享

相关推荐