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!
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

Tom Curry
1,429 PointsOpening a Webpage in the Browser (2 of 2) Help Needed
The member variable 'mUrls' is filled with a few URLs. In the 'onListItemClick()' method, declare and start an Intent that causes the URL tapped on to be viewed in the browser. Hint: The String URL needs to be set as the data for the Intent as a Uri object.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(mUrls);
startActivity(intent);
}
Been stuck for a while now. Not sure how to make it work.
4 Answers

Tom Curry
1,429 PointsI figured it out. For anyone who needs help:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(mUrls[position]));
startActivity(intent);
}

Yachthaven Support
3,121 PointsJoshua, it works because the mUrls array of strings can't be parsed as a single Url, and so as the onClickListener class brings in position as a variable, by setting the specific string in the array of mUrls (using mUrls[position]) you are selecting just the one that was clicked.

Joshua Lopez
8,972 PointsI'm confused on why that works.

Petras Brinko
1,850 PointsThanks, Tom
ms2030
2,973 Pointsms2030
2,973 PointsThanks Tom for posting your answer. That solved my issue about what to do with the position.
Seye Kuyinu
2,581 PointsSeye Kuyinu
2,581 PointsThanks for this! Helped me