Question

I'm trying to learn how to make RSS Reader for my android app by following this tutorial. The feed is generated from a wordpress blog and I want to figure out a way to read by categories. It's currently reading the entire feed items but I'm trying to sort out specific categories from the list.

This is the Activity class to read the feed.

// 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;

}
Was it helpful?

Solution

before adding the items to your list you can check like this:

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

add it to the list because it contains the category you want

}

then add it to the list

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top