0
What does this mean?
TextView name = (TextView) findViewById(R.id.name); What does this line in android mean? And why is the second textView after equals inside a bracket?
3 odpowiedzi
+ 3
The second TextView inside a bracket is to convert the view into the TextView. Like typecasting. In this scenario you don't need any type casting here, so you can remove the
second TextView with the bracket.
TextView name = (TextView) findViewById(R.id.name);
Simply this line is logically equivalent too
int num=(int)5;
Look we are just trying to perform a typecasting with an int, which is not necessary, it could be simply written as this.
int num=5;
Part-2
+ 4
TextView is a type, of Class TextView that extends View class, like any other objects Strings, Integers and so on.
Everything like View, TextView, ImageView, EditText, Button all are classes.
Those classes are predefined, someone has already created those classs and methods so we can use them later in our project. Basically they are prewritten in the API, all necessary hard coding has been already done. All algorithms, attachment, coding and so forth are already done, they have created a backbone, all we are Using is an abstract (brief) terms, behind the scene is hidden so we don't have any troubles.
There's a variable called name of type TextView, which is referenced from the XML layout file where you have added the TextView. simply like finding the text view with help of ID, it'll search for TextView with that particular ID and assign that view to the TextView.
Part-1
0
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
So can i write
TextView someOtherName = findViewById(R.id.name);