android - Set up TextView with method result -


i'm beginner java , stuck in 1 place. have method in class 1

public string saysomething() {     return "blabla"; } 

then in main:

public class mainactivity extends appcompatactivity {     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          textview tw = (textview) findviewbyid(r.id.text1);         tw.settext(saysomething());     } } 

i try set return method textview. have no idea how wanted show want do. how properly?

in short, put saysomething() method in activity class or generate instance of class hosting method , call it:

classname1 classname = new classname1(); textview tw = (textview) findviewbyid(r.id.text1); tw.settext(classname.saysomething()); 

Comments