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
Don Noray
0 PointsChallenge code: Opening a Webpage in the Browser
In the 'onListItemClick()' method, declare and start an Intent that causes the URL tapped on to be viewed in the browser. Here is my code:
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);
}
}
Compilation Error!
3 Answers
Florian Uhlig
2,518 PointsLike Ben said you need to get the String from the array corresponding to the tapped position.
// get string with position as index
String blogUrl = mUrls[position];
// create intent that opens in browser
Intent intent = new Intent(Intent.ACTION_VIEW);
// convert url to uri
intent.setData(Uri.parse(blogUrl));
startActivity(intent);
Ben Jakuben
Treehouse TeachermUrls is an array of Strings, but you just need a single String for the Uri.parse() method. Furthermore, you want to make sure you're getting the correct String from the array that matches the position of the item tapped in the list (i.e. tapping on the third item in the list will give you the third String in the array).
Don Noray
0 PointsThanks!