首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何为Android构建一个RSS阅读器?

如何为Android构建一个RSS阅读器?
EN

Stack Overflow用户
提问于 2011-05-23 15:10:12
回答 3查看 53K关注 0票数 16

我是Android的新手,我正在尝试为android构建一个RSS阅读器。我已经建立了所有的类和XML文件,但它没有给出所需的输出。它只是显示消息No RSS feed available

请有人建议我该怎么做。

这是我从教程中摘取的代码,并试图操纵它-

代码语言:javascript
复制
public final String RSSFEEDOFCHOICE = "http://blog.01synergy.com/feed/";

public final String tag = "RSSReader";
private RSSFeed feed = null;

/** Called when the activity is first created. */

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    // go get our feed!
    feed = getFeed(RSSFEEDOFCHOICE);

    // display UI
    UpdateDisplay();

}


private RSSFeed getFeed(String urlToRssFeed)
{
    try
    {
        // setup the url
       URL url = new URL(urlToRssFeed);

       // create the factory
       SAXParserFactory factory = SAXParserFactory.newInstance();
       // create a parser
       SAXParser parser = factory.newSAXParser();

       // create the reader (scanner)
       XMLReader xmlreader = parser.getXMLReader();
       // instantiate our handler
       RSSHandler theRssHandler = new RSSHandler();
       // assign our handler
       xmlreader.setContentHandler(theRssHandler);
       // get our data via the url class
       InputSource is = new InputSource(url.openStream());
       // perform the synchronous parse           
       xmlreader.parse(is);
       // get the results - should be a fully populated RSSFeed instance, or null on error
       return theRssHandler.getFeed();
    }
    catch (Exception ee)
    {
        // if we have a problem, simply return null
        return null;
    }
}
public boolean onCreateOptionsMenu(Menu menu) 
{
    super.onCreateOptionsMenu(menu);

    menu.add(0,0,0, "Choose RSS Feed");
    menu.add(0,1,0, "Refresh");
    Log.i(tag,"onCreateOptionsMenu");
    return true;
}

public boolean onOptionsItemSelected(Menu item){
    switch (((View) item).getId()) {
    case 0:

        Log.i(tag,"Set RSS Feed");
        return true;
    case 1:
        Log.i(tag,"Refreshing RSS Feed");
        return true;
    }
    return false;
}


private void UpdateDisplay()
{
    TextView feedtitle = (TextView) findViewById(R.id.feedtitle);
    TextView feedpubdate = (TextView) findViewById(R.id.feedpubdate);
    ListView itemlist = (ListView) findViewById(R.id.itemlist);


    if (feed == null)
    {
        feedtitle.setText("No RSS Feed Available");
        return;
    }

    feedtitle.setText(feed.getTitle());
    feedpubdate.setText(feed.getPubDate());

    ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this,android.R.layout.simple_list_item_1,feed.getAllItems());

    itemlist.setAdapter(adapter);

    itemlist.setOnItemClickListener(this);

    itemlist.setSelection(0);

}


 public void onItemClick(AdapterView parent, View v, int position, long id)
 {
     Log.i(tag,"item clicked! [" + feed.getItem(position).getTitle() + "]");

     Intent itemintent = new Intent(this,ShowDescription.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).getPubDate());

     itemintent.putExtra("android.intent.extra.INTENT", b);

     startSubActivity(itemintent,0);
 }


private void startSubActivity(Intent itemintent, int i) {
    // TODO Auto-generated method stub

}

}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-05-23 15:19:34

查看下面的链接,这是开源的Android RSS阅读器,你可以下载代码作为参考

http://code.google.com/p/android-rss/

票数 5
EN

Stack Overflow用户

发布于 2011-05-30 18:49:26

这里有一个关于如何构建Android RSS reder的教程(包括完整的源代码):

part 1 (complete application)

part 2 (application updated to parse image tags from desciption)

part 3 (application update with Android 3.0)

本教程使用SAX解析器,并包含一个完整的Android项目,该项目访问RSS提要,然后在列表视图中显示提要。

似乎仍然有很多人对此感兴趣-所以如果你正在寻找一个带有片段/异步任务等的Android 3.0+,以及完整的应用程序代码,我已经再次更新了帖子和they can be found here!

票数 4
EN

Stack Overflow用户

发布于 2016-03-07 04:47:40

你可以在google-play上下载并查看我的项目。这个项目是关于一些土耳其体育频道馈送。在一个应用程序中有许多通道。

您可以在github上查看项目的源代码。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6093975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档