How is it possible to declare an object without first instantiating it?

Asked

Viewed 25 times

0

I came across a question in android programming, when we declare the views in the java class, as in the example: (Textview txt = (Textview) findViewById (R.id.txt), this View is being used by the class without before it has been instantiated?

1 answer

3

I think you are confusing declaring with initializing/assigning.

On the line

TextView txt = (TextView) findViewById (R.id.txt);

the declaration is being made by

TextView txt

and at the same time, through

= (TextView) findViewById (R.id.txt)

Views are instantiated by Activity during the process of their creation.
The method findViewById(R.id.txt) takes care of returning the view instance whose id is R.id.txt, if there is.

  • Got it. My question was this, where the findViewById(int) method takes care of returning a view instance. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.