2
public class SoccerActivity extends Activity {
private WebView webView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soccer);
webView = (WebView)findViewById(R.id.webview);
String soccerString = QueryYahooSoccer();
Document soccerDoc = convertStringToDocument(soccerString);
String soccerResult = parseSoccerDescription(soccerDoc);
webView.loadData(soccerResult, "text/html", "UTF-8");
}
private String parseSoccerDescription(Document srcDoc){
String soccerDescription="";
NodeList nodeListDescription = srcDoc.getElementsByTagName("description");
if(nodeListDescription.getLength()>=0){
for(int i=0; i<nodeListDescription.getLength(); i++){
soccerDescription += nodeListDescription.item(i).getTextContent()+"<br/>";
}
}else{
soccerDescription = ("No Description!");
}
return soccerDescription;
}
private Document convertStringToDocument(String src){
Document dest = null;
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser;
try {
parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
Toast.makeText(SoccerActivity.this, e1.toString(), Toast.LENGTH_LONG).show();
} catch (SAXException e) {
e.printStackTrace();
Toast.makeText(SoccerActivity.this, e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(SoccerActivity.this, e.toString(), Toast.LENGTH_LONG).show();
}
return dest;
}
private String QueryYahooSoccer(){
String qResult = "";
String queryString = "http://news.yahoo.com/rss/soccer";
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(queryString);
try {
HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();
if (httpEntity != null){
InputStream inputStream = httpEntity.getContent();
Reader in = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(in);
StringBuilder stringBuilder = new StringBuilder();
String stringReadLine = null;
while ((stringReadLine = bufferedreader.readLine()) != null) {
stringBuilder.append(stringReadLine + "\n");
}
qResult = stringBuilder.toString();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
Toast.makeText(SoccerActivity.this, e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(SoccerActivity.this, e.toString(), Toast.LENGTH_LONG).show();
}
return qResult;
}
}
我創建的足球rss像上面那樣運行後運行一個android應用程序它只顯示信息標題鏈接不顯示。什麼是問題你可以任何身體知道請幫助我..如何獲得android的RSS提要
thanku烏拉圭回合的幫助 – user1252191 2012-03-30 11:56:24
您的歡迎......如果你發現我的答案有幫助那麼請標記爲答案,表決了。 – Nimit 2012-04-02 05:05:26