This is on kotlin and it’s WORK.
I want the same on Jetpack Compose.
EXEMPLE ON KOTLIN:
val num1 = findViewById(R.id.valor1)
val num2 = findViewById(R.id.valor2)
val resultado = findViewById<TextView>(R.id.resultado)
val calcular = findViewById<Button>(R.id.calcular)
calcular.setOnClickListener {
val um = num1.text.toString()
val dois = num2.text.toString()
val tres = um.toInt() * dois.toInt()
resultado.text = "$tres"
}
The XML for this kotlin code:
<EditText
android:id="@+id/valor2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:ems="10"
android:hint="Valor 2"
android:inputType="number"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/valor1" />
<TextView
android:id="@+id/resultado"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="50dp"
android:text="Resultado"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/valor2" />
<Button
android:id="@+id/calcular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="50dp"
android:text="Calcular"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/resultado" />