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;
}
}
my created soccer rss feeds like above after that run an android application it displays only information title link is not displayed.what was the problem can you any body knows please help me..
Here is the complete Document and example code.