How to compare user input to a string in Kotlin

403 Views Asked by At

I'm trying to do a little login page that compares user input to a string and lets you past that screen when the password and email are correct but I can't seem to work it out.

`

package com.example.polihack2

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.Button
import android.widget.EditText

val realpw="realpassword"
val realemail="[email protected]"

class SecondActivity : AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?){
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)
        val buttonlogin = findViewById(R.id.login_button) as Button
        /**buttonlogin.setOnClickListener{
            intent = Intent(this, ThirdActivity::class.java)
            startActivity(intent)
        }*/
        var email = findViewById(R.id.email) as EditText
        var password = findViewById(R.id.password) as EditText
        var login_button = findViewById(R.id.login_button) as Button
        login_button.setOnClickListener{
            
        }
    }
}

`

1

There are 1 best solutions below

0
Levent Sürer On

just email and password returns you a Editable. If you want to reach text in those input you should use like this:

if(email.text.toString() == realemail && password.text.toString() == realpw){ intent = Intent(this, ThirdActivity::class.java) startActivity(intent) }