Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- 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;
- }
- public class CustomList extends BaseAdapter {
- private final List<FeedItem> itemList;
- public CustomList(List<URL> urlList) {
- itemList = new ArrayList<FeedItem>();
- for (URL rssUrl: urlList) {
- //TODO your code to extract feed items from a URL
- itemList.addAll(myRssFeed.getList());
- }
- }
- @Override
- public int getCount() {
- return itemList.size();
- }
- @Override
- public Object getItem(int position) {
- return itemList.get(position);
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- if (convertView == null) {
- //TODO inflate your view from XML
- }
- FeedItem feedItem = itemList.get(position);
- //TODO configure convertView using the data in feedItem
- return convertView;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement