Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialdlpuxdzztg
8,243 PointsQuestions.
Hello,
When you create a new project in android studio, you start with a function called 'onCreate'.
1. Does this mean that everything written under this will only happen when they're first created?
Also:
public void onClick(View v)
2. What does 'View v' do?
Thanks!
2 Answers
Kourosh Raeen
23,733 PointsHi Diego - The onCreate() callback method gets automatically called at the beginning of an activity's lifecycle, when the activity is launched but before it is visible. This is where you wire up the UI. If the activity gets killed and is going to get recreated, for example after an orientation change, then onCreate() gets called again. For more information take a look at this video from the Android Activity Lifecycle course: https://teamtreehouse.com/library/android-activity-lifecycle/the-activity-lifecycle/activity-lifecycle-overview
Regarding your second question, v
is a reference to the view that was clicked, such as a button, etc.
Thomas Lian Ødegaard
9,540 Pointshttps://developer.android.com/reference/android/view/View.OnClickListener.html
"View: The view that was clicked."
dlpuxdzztg
8,243 PointsThanks!
If you can, could you also help me with the first question?
dlpuxdzztg
8,243 Pointsdlpuxdzztg
8,243 PointsOkay! Thanks!