views:

231

answers:

1

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.

viewSection.java:

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

public class viewSection extends Activity {

       /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       WebView wv;

       setContentView(R.layout.viewsection);

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

viewsection.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content">
       <WebView android:id="@+id/wv1"
               android:layout_height="wrap_content"
               android:layout_width="fill_parent"
       />
</LinearLayout>
A: 

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).

Roman Nurik
I may look in to the Style text. Changing the layout_height didn't fix it. Any other ideas?
Ian
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
Right on. Taking out the LinearLayout fixed the problem. Thank you soooo much!
Ian
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.
Shadow