I have a demo file in raw folder under res. When i click on a button to open the file a blank screen appears i am unable to resolve the problem.
Here's the code :
For the xml file :
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
For the activity :
package com.ashsoft.basiccprogram;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class First extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.first);
WebView webView = (WebView) this.findViewById(R.id.webView1);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadData(readTextFromResource(R.raw.demo), "text/html", "utf-8");
}
private String readTextFromResource(int resourceID)
{
InputStream raw = getResources().openRawResource(resourceID);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
int i;
try
{
i = raw.read();
while (i != -1)
{
i = raw.read();
}
raw.close();
}
catch (IOException e)
{
e.printStackTrace();
}
return stream.toString();
}
};
I am getting a blank screen. The demo.html is saved in the raw folder.