Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why text of EditText is not chanigng when i click the button

I have a app written in kotlin i want to fill the username field and password field and when i want to click the login button i want that the text of username field should be set to hello but this is not working

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        var username = findViewById<EditText>(R.id.usernameText)
        var password = findViewById<EditText>(R.id.passwordText)
        var btn_Submit = findViewById<Button>(R.id.loginButton)

        btn_Submit.setOnClickListener()
        {
            val user = username.text
            val pass = password.text
            Toast.makeText(this@MainActivity, user, Toast.LENGTH_LONG).show()
            if(user.equals("amar"))
            {
                username.setText("hello")
            }
        }
    }
}

the username field which is placed in ui is of Plain Text and password field is Password
I am very new to this please guide me where i went wrong

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Check this:

    btn_Submit.setOnClickListener()
    {
        val user:String = username.text.toString()
        val pass:String = password.text.toString()
        Toast.makeText(this@MainActivity, user, Toast.LENGTH_LONG).show()
        if(user.equals("amar"))
        {
            username.setText("hello")
        }
    }

or change the if statement like this:

        if(user=="amar"))
        {
            username.setText("hello")
        }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading