12/07/2024

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()
            ,
        )