How to do this math stuff on Jetpack Compose?

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" />

Don’t know why this part miss here:

BUG HERE!
The first EditText do not show here, it’s basicly the same of the second there

There is no direct equivalent to findViewById in compose. Declarative UIs work in a totally different way. This is not a good place to try to learn such basic knowledge. See Thinking in Compose  |  Jetpack Compose  |  Android Developers

1 Like

I know this is diferent, I build the same code in compose already, but, can’t recover the inputField to use like I use there, that’s only a example like I said, is because my compose code is very extensive and have 3 packages and all is easy when you know the code.
:confused: