In my Fragment
I'm displaying the RSS feed from a news page on the Web, but I'm able to get these datas only from one Url
. Then I display the data of this single Url in my Custom Listview
.
So, Is there a way I can show datas from more than one Url displayed in different Listviews but in the same Fragment
?
Perhaps what I am asking is not clear,if so comment and check the image I made below:
Here there's the code that I have in my Fragment:
try {
URL rssUrl = new URL("URL1");
SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
XMLReader myXMLReader = mySAXParser.getXMLReader();
RSSHandler myRSSHandler = new RSSHandler();
myXMLReader.setContentHandler(myRSSHandler);
InputSource myInputSource = new InputSource(rssUrl.openStream());
myXMLReader.parse(myInputSource);
myRssFeed = myRSSHandler.getFeed();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (myRssFeed!=null)
{
ListView list = (ListView)view.findViewById(android.R.id.list);
CustomList adapter = new CustomList(getActivity(),myRssFeed.getList());
adapter.addAll();
list.setAdapter(adapter);
}
else
Toast.makeText(getActivity(), "....",
Toast.LENGTH_LONG).show();
return view;
}
Edit Custom ListView for a Url:
public class CustomList extends ArrayAdapter<RSSItem> {
private static Activity context = null;
private final List<RSSItem> web;
private SharedPreferences mPrefs;
final String read2 = "text1";
final String testoread2 = "img1";
public CustomList(Activity context, List<RSSItem> web) {
super(context, R.layout.custom_list, web);
CustomList.context = context;
this.web = web;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
final View rowView = inflater.inflate(R.layout.custom_list, null, true);
mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
....
return rowView;
}
Any suggestion is appreciated.
EDIT2 What I have now:
try {
URL rssUrl = new URL("URL1");
URL rssUrl2 = new URL("URL2");
SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
SAXParser mySAXParser2 = mySAXParserFactory.newSAXParser();
XMLReader myXMLReader = mySAXParser.getXMLReader();
XMLReader myXMLReader2 = mySAXParser2.getXMLReader();
RSSHandler myRSSHandler = new RSSHandler();
RSSHandler2 myRSSHandler2 = new RSSHandler2();
myXMLReader.setContentHandler(myRSSHandler);
myXMLReader2.setContentHandler(myRSSHandler2);
InputSource myInputSource = new InputSource(rssUrl.openStream());
InputSource myInputSource2 = new InputSource(rssUrl2.openStream());
myXMLReader.parse(myInputSource);
myXMLReader2.parse(myInputSource2);
myRssFeed = myRSSHandler.getFeed();
myRssFeed2 = myRSSHandler2.getFeed();