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);
}}

解决方案 »

  1.   

    rss.xml文件是要自己写的吗?用什么写?
    将rss.xml写好,放在服务器,手机客户端获取就行!
    格式!
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <resource>
         <title>一</title>
         <link>http://www.baidu.com</link>
         ......
        根据自己的客户端情况写吧
      </resource>
    </resources>pc上需要搭建一个服务器,可以是ftp服务器,也可以是http服务器
    推荐使用tomcat,简单使用
    搭建好以后将res.xml放在网站目录下 
    比如网站 http://111.111.11.1:8080/index.asp
    客户端上xml的网址就可以写为
    http://111.111.11.1:8080/res.xml
    楼主试试吧!
      

  2.   

    xml可以放到web站点上或者android项目的assets目录中
      

  3.   

    <!-- XML版本和字符集 -->  
      <?xml version="1.0"?>  
      <!-- RSS版本 -->  
      <rss version="2.0">  
      <!-- 以下为频道信息及新闻列表 -->  
      <channel>  
      <!-- 频道总体信息:开始 -->  
      <!-- 频道标题 -->  
      <title>Lift Off News</title>  
      <!-- 频道链接的总地址 -->  
      <link>http://liftoff.msfc.nasa.gov/</link>  
      <!-- 频道描述文字 -->  
      <description>Liftoff to Space Exploration.</description>  
      <!-- 频道使用的语言(zh-cn表示简体中文) -->  
      <language>en-us</language>  
      <!-- 频道发布的时间 -->  
      <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>  
      <!-- 频道最后更新的时间-->  
      <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>  
      <docs>http://blogs.law.harvard.edu/tech/rss</docs>  
      <!-- 频道生成器 -->  
      <generator>Weblog Editor 2.0</generator>  
      <managingEditor>[email protected]</managingEditor>  
      <webMaster>[email protected]</webMaster>  
      <ttl>5</ttl>  
      <!-- 频道总体信息:结束 -->  
      <!-- 每条RSS新闻信息都包含在item节点中, -->  
      <item>  
      <!-- 新闻标题 -->  
      <title>Star City</title>  
      <!-- 新闻链接地址 -->  
      <link>http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp</link>  
      <!-- 新闻内容简要描述 -->  
      <description>How do Americans get ready to work with Russians aboard the  
      International Space Station? They take a crash course in culture, language  
      and protocol at Russia's Star City.</description>  
      <!-- 新闻发布时间 -->  
      <pubDate>Tue, 03 Jun 2003 09:39:21 GMT</pubDate>  
      <!-- 新闻目录 -->  
      <category>IT</category>  
      <!-- 新闻作者 -->  
      <author>bill</author>  
      <guid>http://liftoff.msfc.nasa.gov/2003/06/03.html#item573</guid>  
      </item>  
      <item>  
      <title>Space Exploration</title>  
      <link>http://liftoff.msfc.nasa.gov/</link>  
      <description>Sky watchers in Europe, Asia, and parts of Alaska and Canada  
      will experience a partial eclipse of the Sun on Saturday, May 31st.</description>  
      Fri, 30 May 2003 11:06:42 GMT</pubDate>  
      <guid>http://liftoff.msfc.nasa.gov/2003/05/30.html#item572</guid>  
      </item>  
      <item>  
      <title>The Engine That Does More</title>  
      <link>http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp</link>  
      <description>Before man travels to Mars, NASA hopes to design new engines  
      that will let us fly through the Solar System more quickly. The proposed  
      VASIMR engine would do that.</description>  
      Tue, 27 May 2003 08:37:32 GMT</pubDate>  
      <guid>http://www.zhanghangfeng.cn/rss.xml</guid>  
      </item>  
      <item>  
      <title>Astronauts' Dirty Laundry</title>  
      <link>http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp</link>  
      <description>Compared to earlier spacecraft, the International Space  
      Station has many luxuries, but laundry facilities are not one of them.  
      Instead, astronauts have other options.</description>  
      Tue, 20 May 2003 08:56:02 GMT</pubDate>  
      <guid>http://liftoff.msfc.nasa.gov/2003/05/20.html#item570</guid>  
      </item>  
      </channel>  
      </rss>  
    这个文件可以放到assert里?你可以详细说明一下步骤吗
      

  4.   

    rss.xml可以放在assert里面
    通过getAssert()获取rss.xml里面的的内容放入string
    通过SAX解析出来就行啦!
      

  5.   

    网址得是阅读器能够访问的。有的网址我们在普通浏览器上可以访问,但在android模拟器上访问不了~~~~