Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. try {
  2. URL rssUrl = new URL("URL1");
  3. SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
  4. SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
  5. XMLReader myXMLReader = mySAXParser.getXMLReader();
  6. RSSHandler myRSSHandler = new RSSHandler();
  7. myXMLReader.setContentHandler(myRSSHandler);
  8. InputSource myInputSource = new InputSource(rssUrl.openStream());
  9. myXMLReader.parse(myInputSource);
  10.  
  11. myRssFeed = myRSSHandler.getFeed();
  12.  
  13. } catch (MalformedURLException e) {
  14. // TODO Auto-generated catch block
  15. e.printStackTrace();
  16. } catch (ParserConfigurationException e) {
  17. // TODO Auto-generated catch block
  18. e.printStackTrace();
  19. } catch (SAXException e) {
  20. // TODO Auto-generated catch block
  21. e.printStackTrace();
  22. } catch (IOException e) {
  23. // TODO Auto-generated catch block
  24. e.printStackTrace();
  25. }
  26.  
  27.  
  28. if (myRssFeed!=null)
  29. {
  30. ListView list = (ListView)view.findViewById(android.R.id.list);
  31. CustomList adapter = new CustomList(getActivity(),myRssFeed.getList());
  32. adapter.addAll();
  33. list.setAdapter(adapter);
  34.  
  35. }
  36. else
  37. Toast.makeText(getActivity(), "....",
  38. Toast.LENGTH_LONG).show();
  39. return view;
  40. }
  41.  
  42. public class CustomList extends ArrayAdapter<RSSItem> {
  43.  
  44. private static Activity context = null;
  45. private final List<RSSItem> web;
  46. private SharedPreferences mPrefs;
  47. final String read2 = "text1";
  48. final String testoread2 = "img1";
  49.  
  50. public CustomList(Activity context, List<RSSItem> web) {
  51. super(context, R.layout.custom_list, web);
  52. CustomList.context = context;
  53. this.web = web;
  54. }
  55. @Override
  56. public View getView(int position, View view, ViewGroup parent) {
  57. LayoutInflater inflater = context.getLayoutInflater();
  58. final View rowView = inflater.inflate(R.layout.custom_list, null, true);
  59. mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
  60.  
  61. if (android.os.Build.VERSION.SDK_INT > 9) {
  62. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  63. StrictMode.setThreadPolicy(policy);
  64. }
  65.  
  66. ....
  67.  
  68.  
  69. return rowView;
  70.  
  71. }
  72.  
  73. public class CustomList extends BaseAdapter {
  74.  
  75. private final List<FeedItem> itemList;
  76.  
  77. public CustomList(List<URL> urlList) {
  78. itemList = new ArrayList<FeedItem>();
  79. for (URL rssUrl: urlList) {
  80. //TODO your code to extract feed items from a URL
  81. itemList.addAll(myRssFeed.getList());
  82. }
  83. }
  84.  
  85. @Override
  86. public int getCount() {
  87. return itemList.size();
  88. }
  89.  
  90. @Override
  91. public Object getItem(int position) {
  92. return itemList.get(position);
  93. }
  94.  
  95. @Override
  96. public long getItemId(int position) {
  97. return position;
  98. }
  99.  
  100. @Override
  101. public View getView(int position, View convertView, ViewGroup parent) {
  102. if (convertView == null) {
  103. //TODO inflate your view from XML
  104. }
  105. FeedItem feedItem = itemList.get(position);
  106. //TODO configure convertView using the data in feedItem
  107. return convertView;
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement