activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="androindian.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"
android:textSize="20sp"
android:textColor="#234098"
android:textAllCaps="true"
android:textStyle="bold|italic"
android:id="@+id/tv"
android:typeface="monospace"
android:gravity="center"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click Me"
android:textSize="20sp"
android:textColor="#234098"
android:textAllCaps="true"
android:textStyle="bold|italic"
android:id="@+id/bt"
android:typeface="monospace"
android:gravity="center"/>
</LinearLayout>
MainActivity.kt
package com.androinidan.button
import androidx.appcompat.app.AppCompatActivity
import android.widget.TextView
import android.os.Bundle
import android.view.View
import android.widget.Button
import com.androinidan.button.R
class MainActivity : AppCompatActivity() {
var textView: TextView? = null
var button: Button? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView = findViewById<View>(R.id.tv) as TextView
button = findViewById<View>(R.id.bt) as Button
button!!.setOnClickListener {
textView!!.text = "Hi Hello Good morning"
}
}
}
output