I just started learning kotlin, and in my app I want to take value placed by user from EditText to my MainActivity and work on it (for example add 1.5 to that value and show that value on the screen), but I have no idea how to do it, the code I wrote so far:
val btnClick= findViewById<Button>(R.id.btn)
val tekstNaButtonie = findViewById<TextView>(R.id.siema)
val mEdit = findViewById<EditText>(R.id.editTextTextPersonName)
val strrr = mEdit.getText()
val strrrr = strrr.toString()
val liczba = strrrr.toFloat()
val liczbaa = liczba + 1.5f
btnClick.setOnClickListener {
tekstNaButtonie.text = liczbaa.toString()
Toast.makeText(this@MainActivity,"Kliknales mnie!",Toast.LENGTH_LONG).show()
}
My Xml:
android:id="@+id/editTextTextPersonName"
android:layout_width="100sp"
android:layout_height="48sp"
android:layout_marginStart="16sp"
android:layout_marginTop="12sp"
android:ems="10"
android:hint="0"
android:importantForAutofill="no"
android:inputType="numberDecimal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
with this code app don't want to start: enter image description here