Take the 2-minute tour ×

I'm a little embarrassed to post this but I can't seem to figure out where I'm going wrong. I've looked at every example and every tutorial and everything looks right to me. Here's what I'm doing. I have a listview that when you click on an item it will take you to a WebView that displays some static formatted text associated with that list entry.

I had it all working with a TextView but I wanted to be able to use HTML formatting for the text and figured the WebView was the way to go. Right now it is just supposed to display a generic link for testing purposes but when the viewContent intent starts it just goes to a black screen. I can go back and pick another entry and it also just shows the black screen.

I'm not sure what code you are going to want to see so here's the viewSection class file and the viewsection.xml layout.


import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class viewSection extends Activity {

   public void onCreate(Bundle savedInstanceState) {
       WebView wv;


       wv = (WebView) findViewById(R.id.wv1);
       wv.loadData("<a href='x'>Hello World! - 1</a>",


       <WebView android:id="@+id/wv1"
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You probably want to set android:layout_height on the WebView to fill_parent. I'm not sure if WebView supports wrap_content.

EDIT: You'll want to set the LinearLayout width and height to fill_parent as well.

Also, if you're using very light HTML styling, you can still use a TextView; there are samples in the API Demos sample app on how to do this (i.e. StyledText.java and Link.java).

share|improve this answer
I may look in to the Style text. Changing the layout_height didn't fix it. Any other ideas? –  Ian Feb 2 '10 at 2:27
See my edit re: LinearLayout width and height. In fact, you probably don't even need a LinearLayout, just put the WebView at the top level. –  Roman Nurik Feb 2 '10 at 4:31
Right on. Taking out the LinearLayout fixed the problem. Thank you soooo much! –  Ian Feb 3 '10 at 4:40
Actually webview does support wrap_content. But taking the webview out of the LinearLayout is voodoo. Also it would be nice if you included the version of the OS you are running the app on. It makes a big difference. –  Kaili Oct 6 '10 at 17:13
This fixed it for me too.. I used: WebView web (new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1f)); –  Jeremy Lee Aug 28 '13 at 18:01
add comment

Your Answer


