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
Douglas Blane
855 PointsOpening a Webpage within the App
Hi Ben, I've almost reached the end of the BlogReader project, adapting it to read my own blog, and it's working well up to this point.
But when I try to implement the code in this video, all that happens, when I tap on a blog name, is that Blog Post flashes briefly onto the screen then disappears and the post opens, as before, in the browser.
I can't see any difference between your code and mine, which I've copied and pasted below.
Hope you can help.
In BlogWebViewActivity :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blog_web_view);
Intent intent = getIntent();
Uri blogUri = intent.getData();
WebView webView = (WebView) findViewById(R.id.webView1);
webView.loadUrl(blogUri.toString());
}
In MainListActivity :
Intent intent = new Intent(this, BlogWebViewActivity.class);
intent.setData(Uri.parse(blogUrl));
startActivity(intent);
And in activity_blog_web_view.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".BlogWebViewActivity" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>