I have this piece of Java code:
MaterialDialog builder = new MaterialDialog.Builder(MainActivity.this)
I want to get the MainActivity object in Kotlin. The automatic conversion breaks at MainActivity.this
.
I have this piece of Java code:
MaterialDialog builder = new MaterialDialog.Builder(MainActivity.this)
I want to get the MainActivity object in Kotlin. The automatic conversion breaks at MainActivity.this
.
Just as you do in java for getting the context of activity as MainActivtiy.this , in kotlin you will get the context as this@MainActivity
Try this instead
If you are calling Activity.this from an inner class, you have to put inner before the class
getActivity()
equivalent isthis@activity_name
in case of builder for materialDialogYou can get a reference to your
MainActivity
object in Kotlin by using a qualifiedthis
. e.g.:You can get the object of activity like this.