Simple example of Button and Toast (Android Kotlin)

exercise_major.xml




    

        

MainActivity.kt

offer android_er.blogspot.com.myapp01

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.see.Look at
import android.widget.Button
import android.widget.Toast

non-public lateinit var btnA: Button
non-public lateinit var btnB: Button

course MainActivity : AppCompatActivity() 
    override enjoyable onCreate(savedInstanceState: Bundle?) 
        super.onCreate(savedInstanceState)
        setContentView(R.format.exercise_major)

        btnA = findViewById(R.id.btn_A)
        btnB = findViewById(R.id.btn_B)

        btnA.setOnClickListener(
             watch: Check out ->
                Toast.makeText(
                    this,
                    "Button A pressed",
                    Toast.Length_Very long,
                ).present()
            ,
        )

        btnB.setOnClickListener(
             watch: Check out ->
                Toast.makeText(
                    this,
                    "Button B pressed",
                    Toast.Length_Extended,
                ).clearly show()
            ,
        )