2012-01-19 11 views
3

我有一個xml文件,我想加載xml內容到一個web視圖,其中web視圖將充氣到一個畫廊。我已經解析並能夠獲得解析的值,但是如何將XML內容加載到Web視圖?我對此毫無頭緒。請有人幫助我。如何加載到web視圖的xml android

+0

你想要什麼? –

回答

3

我認爲你需要顯示標籤內容,

然後分析XML,並顯示網頁流量爲:

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> 
    ]]> 
+0

非常感謝..這幫了我 – cavallo

0

A 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作爲骨架)

+0

我該怎麼做,我只有xml不html.do我必須將xml轉換爲html – cavallo

+0

您必須告訴我該XML包含什麼。請記住,xml本身不能用於呈現網頁。只有當您的文件可以通過Chrome或FireFox等瀏覽器呈現時,WebView才能呈現它。 – Reno

+0

裏諾我已經添加了我的xml請參閱並幫助我請 – cavallo

0

請按照this關於XML解析的android開發者教程,下載示例代碼並根據你的XML文件修改它。它首先解析一個XML,然後創建一個HTML代碼字符串,最後在一個簡單的webView中呈現這個HTML字符串。