10/10/2026

Tech Guru

Trusted Source Technology

Simple example of Button and Toast (Android Kotlin)

Simple example of Button and Toast (Android Kotlin)
Simple example of Button and Toast (Android Kotlin)

action_primary.xml




    

        

MainActivity.kt

deal android_er.blogspot.com.myapp01

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Perspective
import android.widget.Button
import android.widget.Toast

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

class MainActivity : AppCompatActivity() 
    override enjoyment onCreate(savedInstanceState: Bundle?) 
        tremendous.onCreate(savedInstanceState)
        setContentView(R.structure.action_primary)

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

        btnA.setOnClickListener(
             view: See ->
                Toast.makeText(
                    this,
                    "Button A pressed",
                    Toast.Length_Very long,
                ).show()
            ,
        )

        btnB.setOnClickListener(
             check out: Perspective ->
                Toast.makeText(
                    this,
                    "Button B pressed",
                    Toast.Length_Extended,
                ).demonstrate()
            ,
        )
    

Dhanisa Mashilfa
Dhanisa Mashilfa

Dhanisa Mashilfa is a senior technology analyst at DTechGuru covering AI, cloud, cybersecurity, and IoT. 6+ years, 150+ guides. Method: proof-of-concept deployment, security assessment, and cost modeling. Author of 2,429 tech guides since 2022.