Preview:
package com.example.addition2

import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.example.addition2.ui.theme.Addition2Theme

class MainActivity : ComponentActivity() {
    private lateinit var t1:TextView
    private lateinit var et1:EditText
    private lateinit var et2:EditText
    private lateinit var bt1:Button
    private lateinit var bt2:Button
    private lateinit var t2:TextView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    
        setContentView(R.layout.activity_main)
        t1= findViewById(R.id.title)
        et1= findViewById(R.id.num1)
        et2= findViewById(R.id.num2)
        bt1= findViewById(R.id.add)
        bt2= findViewById(R.id.cls)
        t2= findViewById(R.id.res)
        bt1.setOnClickListener {
            var n1=et1.text.toString()
            var  n2=et2.text.toString()
            if(n1.isNotEmpty() && n2.isNotEmpty()) {
                val total = n1.toInt() + n2.toInt()
                t2.text="addition is:$total"
            }
            else{
                t2.text="please enter the values"

            }
        }

    }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter