java - Android create a new Object from findViewById vs casting a findViewById -


i try set text textview in java: first created object this:

//property info textview propertyinfo = (textview) info.findviewbyid(r.id.info); propertyinfo.settext(getinfo());  //production textview production = (textview) info.findviewbyid(r.id.production); production.settext(getproduction()); 

later tried same thing time casted instead of creating new object:

//property info ((textview) info.findviewbyid(r.id.info)).settext(getinfo());  //production ((textview) info.findviewbyid(r.id.production)).settext(getproduction()); 

in test found out second method used less memory when called it. know why, however, want know correct way or how it?

the 2 methods doing same thing.

if need make repeated use of textview setting multiple properties or events first method better avoid multiple calls findviewbyid. necessary if need keep reference view update later in other method.

if using view once in case prefer option 2 since more concise.

it worth noting in first method not creating new object. casting returned view object same second method.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -