在Android中检查密码 [英] Checking password in Android

查看:206
本文介绍了在Android中检查密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查看密码,我在Android中有密码字段

I want to check the password and i have a password field for that in Android

    package com.example.berk4;

    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.Intent;


    public class MainActivity extends Activity implements OnClickListener{



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    EditText et = (EditText)findViewById(R.id.editText1);
    Button buttonEnter = (Button)findViewById(R.id.button1);
    buttonEnter.setOnClickListener(this);


}

@Override
public void onClick(View v) {
    EditText et = (EditText)findViewById(R.id.editText1);
    String password = et.getText().toString();

    et.getEditableText().toString();
    if (password.equals("admin")) {
        Intent intent2 = new Intent("com.example.berk4.screen2");
    startActivity(intent2);

    }else{

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("you suck");
        builder.setMessage("try again");
        builder.setPositiveButton("ok", null);
        AlertDialog dialog = builder.show();
    }

}

}



<当我写一个随机错误的密码时,它工作正常但是当我写了正确的密码时,应用程序关闭,为什么它对我不起作用? (顺便说一句。我有另一个类screen2。)

When i write a random wrong password it works fine but when i write the correct password, the application shuts down, Why it doesnt work for me ? (btw. i have another class screen2.)

推荐答案

启动新活动,就像密码正确一样:

Start New Activity as if password is correct :

 if (password.equals("admin")) {
        Intent intent2 = new Intent(MainActivity.this,screen2.class);
        startActivity(intent2);

    }else{
    // your code here
  }

并确保您已将 AndroidManifest.xml 中的下一个活动添加为:

and also make sure you have added your Next Activity in AndroidManifest.xml as:

.....
<activity android:name=".screen2"></activity>
</application>
.....

这篇关于在Android中检查密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆