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 trial

Android Android Lists and Adapters (2015) Acting on List Item Taps Using a ListView in a Regular Activity

vicente lee
vicente lee
6,271 Points

onItemClick(AdapterView<?> parent, View view, int position, long id)

can someone explain what parent, and view does here? We don't really use them when we create this chunk of code:

public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String dayOfTheWeek = mDays[position].getDayOfTheWeek(); String conditions = mDays[position].getSummary(); String highTemp = mDays[position].getTemperatureMax() + ""; String message = String.format("On %s the high will be %s and it will be %s", dayOfTheWeek, highTemp, conditions); Toast.makeText(DailyForecastActivity.this, message, Toast.LENGTH_LONG).show(); }

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

view is the item in the display that was clicked/tapped and parent is the ListView it's in (or other, like a Spinner). They are passed in case they are needed.