This seems to be the easiest way to get rid of findViewById ()
Go to your Build.Gradle (module: application)
Add the following line
apply plugin: 'kotlin-android-extensions'
- Then he will ask you to synchronize
- Then click
After that, enter your activity file. Say it's a lot of MainActivity.kt
There import import single view
import kotlinx.android.synthetic.main.<layout_name>.<view_name>;
or
To import all views
import kotlinx.android.synthetic.main.<layout_name>.*;
Example: in layout
<Checkbox id="@+/forwardBox" . . . />
is in activity_main layout then import as
import kotlinx.android.synthetic.main.activity_main.forwardBox;
therefore, either in your function or in the class use it directly
forwardBox.isChecked = false
source share