小编Mar*_*ert的帖子

EditText.getText().toString()与其他字符串的比较失败

即使我填写了正确的引脚,Toast仍然拒绝接入访问.

我需要将用户锁定在自助服务终端模式应用中,只有使用正确的引脚,他们才能访问设置和退出选项.

            public void onClick(View v) {

            AlertDialog.Builder alert = new AlertDialog.Builder(FullscreenActivity.this);
            alert.setTitle("PIN:");
            //alert.setMessage("Message");

            final EditText pinEntry = new EditText(FullscreenActivity.this);
            alert.setView(pinEntry);
            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String pin = pinEntry.getText().toString().trim();
                    String secret = "0000";
                    if (pin == secret){
                        Toast.makeText(getApplicationContext(),"Access Approved", Toast.LENGTH_SHORT).show();
                    }
                    else {
                        Toast.makeText(getApplicationContext(),"Access Denied", Toast.LENGTH_SHORT).show();
                    }
                    Toast.makeText(getApplicationContext(),pin, Toast.LENGTH_SHORT).show();
                }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                }
            });
            alert.show();
        }
    });
Run Code Online (Sandbox Code Playgroud)

java string android tostring android-edittext

-3
推荐指数
1
解决办法
1728
查看次数

标签 统计

android ×1

android-edittext ×1

java ×1

string ×1

tostring ×1