I take two EditText and one Button. I want to set a particular username and password, and when I click on the Button if the username and password is correct then open a new intent otherwise display a toast.
I use this code to display different toast but it not works. it always display “incorrect”.
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if((e.getText().toString()=="nishant")&&(e1.getText().toString()=="pawan")){
Toast.makeText(getApplicationContext(), "correct",Toast.LENGTH_LONG).show();
} else
Toast.makeText(getApplicationContext(), "incorrect",Toast.LENGTH_LONG).show();
}
});
Try again like this,change “==” with “equals”: