AJIBOLA ODUJOLE
05/02/2021, 11:05 AMprivate fun signIn() {
val email = findViewById<TextInputEditText>(R.id.email_edit_text)
val password = findViewById<TextInputEditText>(R.id.password_edit_text)
val signInButton = findViewById<MaterialButton>(R.id.next_button)
signInButton.setOnClickListener(){
if (email.toString().isEmpty() || password.toString().isEmpty()){
Toast.makeText(this, "Email or Password is not Provided", Toast.LENGTH_SHORT).show()
} else {
if (email.toString() == "<mailto:ajibs@gmail.com|ajibs@gmail.com>" && password.toString() == "234567"){
val intent = Intent(this, ViewActivity::class.java)
startActivity(intent)
} else {
Toast.makeText(this, "Wrong email or password", Toast.LENGTH_LONG).show()
}
}
}
}
Hello everyone,
A newbie on this streets, I have login screen I created It's failing to go to the next screen. Please feedback on the code block. Its output is always wrong email or passwordJoaquim Ley
05/02/2021, 11:26 AM.toString()
to your TextView
references and not the actual text. Try to change to this:
if (email.getText().toString().isEmpty() || password..getText().toString().isEmpty()){
Toast.makeText(this, "Email or Password is not Provided", Toast.LENGTH_SHORT).show()
} else {
if (email..getText().toString() == "<mailto:ajibs@gmail.com|ajibs@gmail.com>" && password..getText().toString() == "234567"){
val intent = Intent(this, ViewActivity::class.java)
startActivity(intent)
} else {
Toast.makeText(this, "Wrong email or password", Toast.LENGTH_LONG).show()
}
}
It should work. Also take a look at some the util methods Kotlin has for text such as .isEmpty()
, .isNotEmpty()
, .isNullOrBlank()
etc.AJIBOLA ODUJOLE
05/02/2021, 11:34 AM.text
instead of getText()
after.Joaquim Ley
05/02/2021, 11:53 AMEditable
the TextInputEditText
returns.