https://kotlinlang.org logo
#android
Title
# android
a

AJIBOLA ODUJOLE

05/02/2021, 11:05 AM
Copy code
private 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 password
j

Joaquim Ley

05/02/2021, 11:26 AM
The issue here is you are doing
.toString()
to your
TextView
references and not the actual text. Try to change to this:
Copy code
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.
a

AJIBOLA ODUJOLE

05/02/2021, 11:34 AM
• Thank you @Joaquim Ley. I really appreciate the help. I fixed it and the IDE recommended I use
.text
instead of
getText()
after.
👍 1
j

Joaquim Ley

05/02/2021, 11:53 AM
Yes because you are using Kotlin, but I thoought it would be better for you to read/know it is a method on the
Editable
the
TextInputEditText
returns.
8 Views