Android TextView-Button Kotlin Tutorial – TextView-Button Kotlin Example

TextView:

TextView is android widget for display any kind of text or strings.

Button:

Button is android widget for clickable touch events.Button can listen to click events.

Tutorial:

Step 1:

Open up Android Studio Project through res -> layout -> activity_main.xml (or) main.xml and add below code or just drag and drop the switch to design XML file.



    
    

Step 2:

Add below code in MainActivity.kt

package com.bytelogs.textviewbuttonkotlin

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle
import android.view.View
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        button.setOnClickListener(View.OnClickListener {
            textView.setText("This is changed onClick")
        })

    }
}