How to get editText in kotlin and display with toast.
var editTextHello = findViewById(R.id.editTextHello)
I tried this but shows object
Toast.makeText(this,editTextHello.toString(),Toast.LENGTH_SHORT).show()
How to get editText in kotlin and display with toast.
var editTextHello = findViewById(R.id.editTextHello)
I tried this but shows object
Toast.makeText(this,editTextHello.toString(),Toast.LENGTH_SHORT).show()
To maintain the standard syntax of Kotlin use
var editText: EditText = findViewById(R.id.editTextHello)
In Kotlin calling .text on your EditText is fine no need to do getText or toString
with button click
Even don't need findViewById
This is Kotlin, not java. You do not need to get the id of it. In kotlin, just write:
use the beauty of kotlin ;-)
P.s: BTW, better to choose xml IDs like edx_hello and for the kotlin part, var editTextHello. Then you can differentiate between xml vars and kotlin vars.
use
editTextHello.text
Use this instead it's working fine
If you make
edittext
as nullable then the line would be