Skip to content Skip to sidebar Skip to footer

How To Load A Xml Into A Webview Android

I have an xml file and I want to load the xml content to a web view where the web view will be inflated to a gallery. I have parsed and able to get the parsed values, but how do I

Solution 1:

I think you need to show content in tag,

then parse your xml, and display webview as:

myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadDataWithBaseURL(null, myPreviewContents, mime, encoding, null);

where myPreviewContents are:

<p>Earlyin my career I took responsibility for managing people. I managed up to 250 highly trained professionals who worked as a tight-knit team. It didn’t matter that I was the youngest person in the team! For over 20 years I’ve been working with individuals and organizations to help them improve their management of people. This has ranged from military personnel to entrepreneurs, from charities to government departments. I’ve learned many secrets and tricks over these years. Some I’ve discovered for myself, but many I’ve learned from others. Humans are wonderfully inventive!</p>
        <p>This book aims to help you improve your skills at managing people – to help you find ways in which everybody benefits. It contains 50 secrets, grouped into seven themed chapters.</p><p><ul><li><spanclass='pointHeading'>Build on a strong foundation.</span><spanclass='normalText'>You must understand what type of leader or manager you want to be. Your employer may give guidelines, but you must exert control over your day-to-day behaviour.</span></li><li><spanclass='pointHeading'>Create a great team.</span><spanclass='normalText'>This shows how to choose the right people and quickly build a functioning team.</span></li><li><spanclass='pointHeading'>Set goals and targets.</span><spanclass='normalText'>By setting people effective targets and goals, you can monitor progress and offer appropriate rewards.</span></li><li><spanclass='pointHeading'>Motivate yourself and your people.</span><spanclass='normalText'>Implementing ways to motivate people is ultimately much easier than having to cajole and constantly monitor unmotivated people.</span></li><li><spanclass='pointHeading'>Manage good performance.</span><spanclass='normalText'>You need to recognize good performance – reward it, develop it, perpetuate it and spread it to others.  Otherwise you will lose your good performers and be left only with the poor ones.</span></li><li><spanclass='pointHeading'>Manage poor performance.</span><spanclass='normalText'>Some managers find ways of managing around poor performance without tackling the poor performance itself. However, this encourages more poor performance, from both the original perpetrator and everyone else. Know how to tackle the problems head on.</span></li><li><spanclass='pointHeading'>Develop your people.</span><spanclass='normalText'>Though often overlooked by managers, another fundamental task is developing people. You need to improve the less able, stretch and reward the able, plan succession for the future and mentor your people’s changing needs. </span></li></ul></p><p>Managing people is a hugely complex area in which you never stop learning. The secrets contained in this book will help you make massive strides towards succeeding in this fascinating role.</p>
    ]]>

Solution 2:

You can use xsl to transform your xml, then load the resulting string into the webivew (webview.loaddata, I believe).

See Android: Convert xml using xslt for example transforming xml.

Solution 3:

A xml file is not always a webpage. You have to give a valid web page in loadUrl() like

  wv.loadUrl("http://www.bbc.co.uk"");

Or use this is you have raw html :

 String summary = "<html><body>You scored <b>192</b> points.</body></html>";
 webview.loadData(summary, "text/html", null);

(Yes, Android uses xml files for it's UI. It inflates Views using the xml as a skeleton )

Solution 4:

Please follow this android developer tutorial on XML parsing, download the sample code and modify it according to your XML file. It starts by parsing an XML, then it goes on creating an HTML code string and at the end it renders this HTML string in a simple webView.

Post a Comment for "How To Load A Xml Into A Webview Android"