我有一个xml文件,我想将xml内容加载到Web视图,其中Web视图将被扩展到库。我已经解析并能够获取解析的值,但是如何将xml内容加载到Web视图?我对它一无所知。请有人帮助我。
答案 0 :(得分:4)
我认为你需要在标签中显示内容,
然后解析您的xml,并将webview显示为:
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadDataWithBaseURL(null, myPreviewContents, mime, encoding, null);
其中myPreviewContents
是:
<p>Early in 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>
<span class='pointHeading'>Build on a strong foundation.</span><span class='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>
<span class='pointHeading'>Create a great team.</span><span class='normalText'>This shows how to choose the right people and quickly build a functioning team.</span>
</li>
<li>
<span class='pointHeading'>Set goals and targets.</span><span class='normalText'>By setting people effective targets and goals, you can monitor progress and offer appropriate rewards.</span>
</li>
<li>
<span class='pointHeading'>Motivate yourself and your people.</span><span class='normalText'>Implementing ways to motivate people is ultimately much easier than having to cajole and constantly monitor unmotivated people.</span>
</li>
<li>
<span class='pointHeading'>Manage good performance.</span><span class='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>
<span class='pointHeading'>Manage poor performance.</span><span class='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>
<span class='pointHeading'>Develop your people.</span><span class='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>
]]>
答案 1 :(得分:0)
xml
文件并不总是网页。您必须在loadUrl()
中提供有效的网页
wv.loadUrl("http://www.bbc.co.uk"");
或者使用这个你有原始的html:
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
(是的,Android使用xml文件作为它的UI。它使用xml作为骨架来膨胀视图)
答案 2 :(得分:0)
您可以使用xsl转换xml,然后将生成的字符串加载到webivew(webview.loaddata,我相信)。
请参阅Android: Convert xml using xslt,例如转换xml。
答案 3 :(得分:0)
请关注有关XML解析的this android开发人员教程,下载示例代码并根据您的XML文件进行修改。它首先解析XML,然后继续创建HTML代码字符串,最后在简单的webView中呈现这个HTML字符串。