-2

I know this is wrong pls help Search all over Yt and nothing on how to do it :( need to learn how to use maths with Variable

package com.example.myapplication

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_calc.*


class Calc : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_calc)


        var need = findViewById<TextView>(R.id.t_need)
        var money = findViewById<TextView>(R.id.t_money)
        var debt = findViewById<TextView>(R.id.t_debt)

        var b_calc = findViewById<TextView>(R.id.b_calc)


        b_calc.setOnClickListener {
            val diffrence = Money - debt         

            need.text = diffrence
       }
   }
}
Ryan M
  • 18,333
  • 31
  • 67
  • 74

1 Answers1

0

When you get text from a textview its usually a Charsequence therefore, you first need to Parse it to int. An example would be

var moneyText = findViewById<TextView>(R.id.t_money)
var money = moneyText.toString().toInt()

From there, you can do this money - debt or with Kotlin you can do money.minus(debt) you can check out Kotlin arithmetic functions here.

Evans Chepsiror
  • 376
  • 4
  • 9