i have created a login page when i enter username and password(if both are equal) it is used to login but the username and password are left blank and when i click on login button on emulator its shows the login succesful
it should not login when the username and password are left balnk
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtUserName=(EditText)this.findViewById(R.id.txtUname);
txtPassword=(EditText)this.findViewById(R.id.txtPwd);
btnLogin=(Button)this.findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if((txtUserName.getText().toString()).equals(txtPassword.getText().toString())){
Intent myIntent = new Intent(v.getContext(), SaveData.class);
startActivityForResult(myIntent, 1);
Toast.makeText(LoginappActivity.this, "Login Successful",Toast.LENGTH_LONG).show();
} else{
Toast.makeText(LoginappActivity.this, "Invalid Login",Toast.LENGTH_LONG).show();
}
}
});
}
}
Just add condition
txtUserName.getText().toString().length() > 0with&& operatorinif