
- Forum posts: 1
Apr 25, 2016, 9:52:46 PM via Website
Apr 25, 2016 9:52:46 PM via Website
Hi! I just started learning Android Development from "developer . android . com / develop / index . html" (Sorry new users not allowed to post links so I had to put a spaces)
I reached on this part "Starting Another Activity (developer . android . com / training / basics / firstapp / starting-activity . html)". Here I have a part of code which is working fine but I don't understand how it works and want to know about it. The code is following:
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.content);
layout.addView(textView);
Now I have 2 Questions:
- In first line of this code; why does the TextView(this) constructor need a Context as it's parameter ?
- This code is in an Activity Class and R.id.content identifies a RelativeLayout in same Activity's xml file now what I understand is that the identifier "layout" refers to a copy of R.id.content casted to RelativeLayout
And the question is
i. if my understanding is correct then "layout" is just a copy of RelativeLayout so adding textView to this copy should not make textView visible as it's not added to actual RelativeLayout in the xml file but only to it's copy
ii. if my understanding is not correct then please correct me and tell me how this works and makes textView visible