0

我正在尝试按照本教程学习如何为我的 android 应用程序制作 RSS 阅读器。提要是从 wordpress 博客生成的,我想找出一种按类别阅读的方法。它目前正在阅读整个提要项目,但我正在尝试从列表中整理出特定类别。

这是用于读取提要的 Activity 类。

// Connected - Start parsing
        new AsyncLoadXMLFeed().execute();

    }

}

private void startLisActivity(RSSFeed feed) {

    Bundle bundle = new Bundle();
    bundle.putSerializable("feed", feed);

    // launch List activity
    Intent intent = new Intent(SplashActivity.this, GridActivity.class);
    intent.putExtras(bundle);
    startActivity(intent);

    // kill this activity
    finish();

}

private class AsyncLoadXMLFeed extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... params) {

        // Obtain feed
        DOMParser myParser = new DOMParser();
        feed = myParser.parseXml(http://mywordpressblog.com/feed/);
        if (feed != null && feed.getItemCount() > 0)
            WriteFeed(feed);
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);

        startLisActivity(feed);
    }

}

// Method to write the feed to the File
private void WriteFeed(RSSFeed data) {

    FileOutputStream fOut = null;
    ObjectOutputStream osw = null;

    try {
        fOut = openFileOutput(fileName, MODE_PRIVATE);
        osw = new ObjectOutputStream(fOut);
        osw.writeObject(data);
        osw.flush();
    }

    catch (Exception e) {
        e.printStackTrace();
    }

    finally {
        try {
            fOut.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

// Method to read the feed from the File
private RSSFeed ReadFeed(String fName) {

    FileInputStream fIn = null;
    ObjectInputStream isr = null;

    RSSFeed _feed = null;
    File feedFile = getBaseContext().getFileStreamPath(fileName);
    if (!feedFile.exists())
        return null;

    try {
        fIn = openFileInput(fName);
        isr = new ObjectInputStream(fIn);

        _feed = (RSSFeed) isr.readObject();
    }

    catch (Exception e) {
        e.printStackTrace();
    }

    finally {
        try {
            fIn.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return _feed;

}
4

1 回答 1

0

在将项目添加到您的列表之前,您可以像这样检查:

if(item.getCategory().contains("categorytoshow")){

将其添加到列表中,因为它包含您想要的类别

}

然后将其添加到列表中

于 2013-04-15T14:57:44.023 回答