Reputation: 13165
I am adding webview
in table row
and loading data, but data is not displaying for me, can anybody tell what is problem. If it linear layout
working but not working in table layout
with table row?
*main.xml*
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<WebView android:id="@+id/link4_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
</LinearLayout>
SampleWebCheckActivity.java
package com.samplecheck;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.util.Linkify;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.TextView;
public class SampleWebCheckActivity extends Activity
{
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView wv=(WebView)findViewById(R.id.link4_view);
String data="sample 1234 2345 5678 123456 ";
wv.loadDataWithBaseURL(null, data, "text/html", "UTF-8", null);
// wv.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, failUrl)(data, "text/html", "UTf-8");
}
}
Even I used loadData it's not working.
Upvotes: 1
Views: 2729
Reputation: 1961
When I have main.xml like this...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow >
<android.webkit.WebView
android:id="@+id/webView1"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</TableRow>
</TableLayout>
</LinearLayout>
And code like this...
WebView webView = (WebView) findViewById(R.id.webView1);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.loadUrl("file:///android_asset/flashcard.html");
And an HTML file like this...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>temp</title>
</head>
<body style="background-color: black; color: white;">
<p>
<strong>Hello</strong> World!
</p>
<p>This is too cool</p>
</body>
</html>
It does exactly what the original poster describes. I was required to not put the WebView inside of a TableLayout/TableRow combination before it would work consistently. Further more, it was working, then not working, depending on the spaces or something in the HTML file.
To me, this looks very much like a bug. Android development in general is very awkward and buggy. You have to get things just right, or they simply don't work. I love android overall, but the development sucks.
Upvotes: 1
Reputation: 14027
You're providing null
for the first parameter of loadDataWithBaseURL which will defaults to
about:blank
.
Try this:
browser.loadData("<html><body>Hello, world!</body></html>","text/html", "UTF-8");
WebView on Android Developer has a very nice explanation actually.
Upvotes: 1