I'm building an RSS feed reader by following the example from this site:
https://www.androidpit.com/java-guide-2-program-your-own-rss-reader
At the moment, when you click on a feed title, nothing happens. What I want it to do is to open the corresponding link in a browser but I've not been able to figure it out.
I've tried this:
private String readItem(XmlPullParser parser) throws XmlPullParserException, IOException {
String result = null;
parser.require(XmlPullParser.START_TAG, null, "item");
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("title")) {
result = readTitle(parser);
} else {
skip(parser);
}
}
return result;
}
// Processes link tags in the feed.
private List<String> readLink(XmlPullParser parser) throws IOException, XmlPullParserException {
ArrayList<String> link = new ArrayList<>();
parser.require(XmlPullParser.START_TAG, null, "link");
link.add(readText(parser));
parser.require(XmlPullParser.END_TAG, null, "link");
return link;
}
// Processes title tags in the feed.
private String readTitle(XmlPullParser parser) throws IOException, XmlPullParserException {
parser.require(XmlPullParser.START_TAG, null, "title");
String title = readText(parser);
parser.require(XmlPullParser.END_TAG, null, "title");
return title;
}
I end up with a warning that says the method readLink is never used locally. I'm not sure whether I should alter the readItem method because there is a readChannel method that requires the value that is returned to be a string.
When I use public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id); ... }
with a Toast, I'm able to see the position of the Item that was clicked but when I use this the app crashes.
Uri uri = Uri.parse(link.get(position));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
So my question is: how do I make a browser open that goes to the corresponding title's link? I'm very new with java and android development so please bear with me.
P.S I've already set my ListView as clickable.