0

My webview in my application does not show up. I went to the interwebs to find an answer, but I found nothing, just tutorials on how to use the control. I am trying to load a html file, but it is not showing.

I added the user permission 'Internet' to my manifest.

Here is my layout:

<TableLayout 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=".MainActivity" >

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:visibility="visible" >

        <WebView
            android:id="@+id/wvInfo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </TableRow>
</TableLayout>

I have a file, 'filename.html' in my assets folder.

The following code is in the onCreate:

  WebView wvinfo = (WebView) findViewById(R.id.wvInfo);
  wvinfo.loadUrl("file:///android_asset/filename.html");

When I load the program on my phone, nothing shows up. I also tried to load an url, "http://www.google.com" and still nothing shows. I am stumped. Any ideas?

1
  • On local files, i would use loadData(html, "text/html", null);. You could also show us the manifest, or the parts you edited. Commented May 16, 2013 at 5:47

3 Answers 3

1

Try the below code in your layout file

<TableLayout 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"
    >



        <WebView
            android:id="@+id/wvInfo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

</TableLayout>
Sign up to request clarification or add additional context in comments.

Comments

0

My guess is that you haven't setContent the layout inside onCreate().

Try like this ...

setContentView(R.layout.webview_layout);

Comments

0

Why are you using a Table Layout for a Web view? Instead use a Linear or Relative Layout.

Try adding this

WebView wvinfo = (WebView) findViewById(R.id.wvInfo);
        wvinfo .getSettings().setJavaScriptEnabled(true);        
       wvinfo.loadUrl("file:///android_asset/filename.html");

Let me know if it works.

4 Comments

Is it really necessary to have RelativeLayout or LinearLayout as a parent layout to Webview??? I don't think so.....
@user2252502: it is not necessary .try the below code <TableLayout xmlns:android="schemas.android.com/apk/res/android" xmlns:tools="schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <WebView android:id="@+id/wvInfo" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </TableLayout>
It is not necessary. Using table row too doesn't seem too good. So in order to remove table row I told so as done by Praveena.
@Oam Why you have enabled the JS here? When it might not be necessary

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.