android studio - Global object declaration in kotlin -


how declare objects globally in kotlin in java textview tv;.

or method call same variable in different methods/functions.

override fun oncreate(savedinstancestate: bundle?) {     super.oncreate(savedinstancestate)     setcontentview(r.layout.activity_main)      val textview: textview = findviewbyid(r.id.texfirst) textview       textview.setonclicklistener {         toast.maketext(applicationcontext,"welcome kotlin ! $abc "+textview.text, toast.length_long).show()     }      myfunction(textview) }  fun myfunction(mtextv : textview) {     toast.maketext(applicationcontext,"this  new  $abc "+mtextv.text, toast.length_long).show() } 

see above code i've separate function parameter of textview. want textview object @ second function. question is: possible call function without parameter , able textview object @ myfunction().

learning kotlin in android studio. hope question clear .

the 1 mentioning class property.

for case, need declare textview in activity class , assignment calling findviewbyid() in oncreate().

class youractivity {      lateinit var textview: textview      override fun oncreate(savedinstancestate: bundle?) {         super.oncreate(savedinstancestate)         setcontentview(r.layout.activity_main)          textview = findviewbyid(r.id.texfirst) textview         //implementation     }      fun myfunction() {         toast.maketext(applicationcontext, "this  new $abc " + textview.text, toast.length_long).show()     } } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -