Images are not displayed while loading html file in android web view

dollor

New Member
I need to load a html file which will display images in android emulator. I have a separate css file and html fie and images to be displayed in /assets folder of my application. I read the css file and html file using getAssets(). I tried to load the html file using loadData() method because i am in the situation to use only string to get html file in a string and load the html file only by using that string but not by using "file:///android_asset/eppi.html". Can anyone say the solution?.You can understand from my following code.thanks in advance.my MainActivity.java code:\[code\] package com.exercise.AndroidHTML; import java.io.InputStream; import java.io.IOException; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.webkit.WebSettings; import android.webkit.WebView; import android.content.res.AssetManager; public class AndroidHTMLActivity extends Activity { WebView myBrowser;String html;String css;String HTML; /** Called when the activity is first created. */ @SuppressLint("SetJavaScriptEnabled")@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myBrowser = (WebView)findViewById(R.id.mybrowser); AssetManager assetmanager=getAssets(); InputStream input; try{ input= assetmanager.open("eppi.html"); int size=input.available(); byte[] buffer=new byte[size]; input.read(buffer); input.close(); html=new String(buffer); } catch (IOException e){ e.printStackTrace(); } try{ InputStream input1= assetmanager.open("eppi.css"); int size=input1.available(); byte[] buffer=new byte[size]; input1.read(buffer); input1.close(); css=new String(buffer); }catch (IOException e){ e.printStackTrace(); } HTML=css+html; myBrowser.getSettings().setJavaScriptEnabled(true); WebSettings settings = myBrowser.getSettings(); settings.setDefaultTextEncodingName("utf-8"); myBrowser.loadData(HTML,"text/html","utf-8"); } }\[/code\]my eppi.css file:\[code\]<html><head><style>#header{height:80px;width:320px;position:absolute;background-color:#000000;}#text{height:80px;width:159px;position:absolute;color:#806C00;}#logo{top:2px; left:200px;height:80px;width:97px;position:absolute;}#image{top:79px;height:80px;width:159px;position:absolute;}#image1{top:79px;left:159px;height:80px;width:161px;position:absolute;}#image2{top:158px;height:80px;width:159px;position:absolute;}#image3{top:158px;left:159px;height:80px;width:161px;position:absolute;}#body{margin:0;padding:0;}</style></head>\[/code\]my eppi.html code:\[code\]<body id="body"><div id="header"><div id="text"><center>h4><b><i>The Epping ClubWelcomes You</i></b></h4></center></div><div id="logo"><img src="http://stackoverflow.com/questions/15571894/logo.png" width="100" height="75"></div></div><div id="image"><a href="http://stackoverflow.com/questions/15571894/Media.html"><img src="http://stackoverflow.com/questions/15571894/myclub.png" width="159" height="80"/></a></div><div id="image1"><a href="http://stackoverflow.com/questions/15571894/Trading.html"><img src="http://stackoverflow.com/questions/15571894/specialoffers.png" width="161" height="80"/></a></div><div id="image2"><a href="http://stackoverflow.com/questions/15571894/Hours.html"><img src="http://stackoverflow.com/questions/15571894/week.png" width="159" height="80"/></a></div><div id="image3"><a href="http://stackoverflow.com/questions/15571894/Release.html"><img src="http://stackoverflow.com/questions/15571894/events.png" width="161" height="80"/></a></div></body></html>\[/code\]
 
Back
Top