java - Android - I need some clarifications -


1.i have textview id textview1

i.

textview tv = (textview) findviewbyid(r.id.textview1); tv.settext("hellow world"); 

or without creating tv,

((textview) findviewbyid(r.id.textview1)).settext("hellow world"); 

ii.

textview tv = (textview) findviewbyid(r.id.textview1); tv.settext("hellow world"); tv.settextsize(somevalue); tv.settag("title"); 

or

((textview) findviewbyid(r.id.textview1)).settext("hellow world"); ((textview) findviewbyid(r.id.textview1)).settextsize(somevalue); ((textview) findviewbyid(r.id.textview1)).settag("title"); 

which approach in both cases , what's difference.

2.similerly have string childname need access 3 methods

i.i can create field variable childname, , can access 3 methods

ii.passing variable through each methods like,

setchildfragment(childname); 

in

public setchildfragment(string childname){ . . . setchildview(childname); } 

and in ,

public setchildview(string childname){ . . . setchildtitle(childname); } 

finally in textview,

public setchildtitle(string childname){  ((textview) findviewbyid(r.id.title)).settext("hellow world"); } 

which approach better, , why !!!

thanks in advance

for first part frankly difference between approach i , ii since ii has no reference textview object might gc collected sooner, although can achieve same writing tv=null; after use i. in case difference not significant.

for second part better store reference view , call methods on instead of repeatedly calling findviewbyid(r.id.textview1), expensive operation leads layout tree traversal , can performance hit if layout huge or complex. in case i better.

the third part again won't make noticeable performance difference referencing variable or passing them function parameter not major performance issue.

to increase performance of app consider designing layout , use practices android docs read this more info


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -