android开发一个简单的rss阅读器,求
rss.xml文件是要自己写的吗?用什么写?
package com.eoeAndroid.RSS;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
public class ActivityMain extends Activity implements OnItemClickListener {
public final String RSS_URL="";
//这个网址要是什么才行?
public final String tag=this.getClass().getName();
private RSSFeed feed=null;
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
feed=getFeed(RSS_URL);
showListView();
}
private RSSFeed getFeed(String urlString)
{
try
{
URL url=new URL(urlString);
SAXParserFactory factory=SAXParserFactory.newInstance();
SAXParser parser=factory.newSAXParser();
XMLReader xmlreader=parser.getXMLReader();
RSSHandler RSSHandler=new RSSHandler();
xmlreader.setContentHandler(RSSHandler);
InputSource is=new InputSource(url.openStream());
xmlreader.parse(is);
return RSSHandler.getFeed();
}
catch(Exception ee)
{
return null;
}
}
private void showListView()
{
ListView itemlist=(ListView)findViewById(R.id.itemlist);
if(feed==null)
{
setTitle("访问的RSS无效");
return;
}
SimpleAdapter adapter=new SimpleAdapter(this,feed.getAllItemsForListView(),android.R.layout.simple_list_item_2,new String[] {RSS.TITLE,RSS.PUBDATE},new int[]{android.R.id.text1,android.R.id.text2});
itemlist.setAdapter(adapter);
itemlist.setOnItemClickListener(this);
itemlist.setSelection(0);
}
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// TODO Auto-generated method stub
Intent itemintent=new Intent(this,ActivityShowDescription.class);
Bundle b=new Bundle();
b.putString("title", feed.getItem(position).getTitle());
b.putString("description", feed.getItem(position).getDescription());
b.putString("link", feed.getItem(position).getLink());
b.putString("pubdate", feed.getItem(position).getPudDate());
itemintent.putExtra("Android.intent.extra.RSS", b);
startActivityForResult(itemintent,0);
}
}