I’m trying to pull a line from an EditText and compare to a pin. If it’s the correct pin it displays authorized, otherwise it displays it’s the wrong pin. I can’t get the 1234 to equal 1234 – it always says Pin Invalid.
Context context = this;
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Pin Entry");
final EditText pinEntry = (EditText) dialog.findViewById(R.id.pinAuth);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButton);
dialogButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
CharSequence alertText;
int duration = Toast.LENGTH_SHORT;
CharSequence pint = pinEntry.getText();
if(pint != "1234")
{
alertText = "Pin invalid.\nPlease try again.";
Toast toast = Toast.makeText(context, alertText, duration);
toast.show();
updateList();
}
else if(pint == "1234")
{
alertText = "Pin authorized";
Toast toast = Toast.makeText(context, alertText, duration);
toast.show();
}
dialog.dismiss();
}
});
dialog.show();
}
Change
to