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 Build a Blog Reader Android App Using Intents to Display and Share Posts Opening a Webpage in the Browser

Stuck on this challenge

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.view.View;
import android.view.ListView;
import android.content.Intent;
import android.net.Uri;

public class CustomListActivity extends ListActivity {

    protected String[] mUrls = { "http://www.teamtreehouse.com", "http://developer.android.com", "http://www.github.com" };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_list);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mUrls);
        setListAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
            super.onListItemClick(l, v, position, id);
        String maylo = mUrls.getStringArray(position);
        Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("mUrls"));
                startActivity(intent);
    }
}

I'm stuck because I don't know how to go about setting the position the URL is in when tapped. please help! this is the code that i have but i'm confused about what to do. Thanks! edit: I have been trying some crazy things.. I updated the code here because it gives better context. this isn't even a try anymore.

2 Answers

You are really close, but have two problems in your code.

  1. You aren't retrieving the String from the mUrls[] array correctly. Try String maylo = mUrls[position];
  2. In Uri.parse() you want to pass in your maylo String variable that you created.

This should point you in the right direction. Let me know if you need more help. Keep coding!

thanks! that was exactly what i needed.