I came across a question in android programming when declaring 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 have you been instantiated?
I came across a question in android programming when declaring 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 have you been instantiated?
I think you're confusing declare with initialize / assign.
On line
TextView txt = (TextView) findViewById (R.id.txt);
The declaration is being made through
TextView txt
and at the same time the assignment, through
= (TextView) findViewById (R.id.txt)
Views are instantiated by Activity during the process of its creation.
The findViewById(R.id.txt)
method takes care of returning the instance of the view whose id is R.id.txt
, if any.