Creates extension functions to map layout views to typed activity properties.
Given this layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/edit"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
The KotlinX compiler will generate extension functions for typed access to declared views without the need for declarations or casting. All that is required is the import to kotlinx.android.synthetic.main...
import kotlinx.android.synthetic.main.activity_new_activity.*
class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_new_activity)
textView.setText("This is text view")
edit.setText("This is edit text view")
val myView = TextView(this)
myView.setText("This is my view")
container.addView(myView)
}
}