xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.boxunpark.www.kotlinapplication.MainActivity">
<Button
android:id="@+id/hello_text"
android:layout_width="match_parent"
android:layout_height="45dp"
android:text="Hello World!" />
<Button
android:id="@+id/click"
android:layout_width="match_parent"
android:layout_height="45dp"
android:text="click" />
</LinearLayout>
//The first way to click
hello_text.setOnClickListener {
...
}
//The second way to click
click.setOnClickListener({ view ->
...
})
When implemented in java, we are like this:
startActivity(new Intent(this,SecondActivity.class));
Implementation using Kotlin
startActivity(Intent(this@MainActivity, SecondActivity::class.java))
TextView hello_text=(TextView)findViewById(R.id.hello_text)
hello_text.settext("Hello world")
hello_text.text="Hello world"