views:

14

answers:

0

Hi - I'm trying to use Fedor's LazyAdapter, but keep getting a "Source Not Found" error when I return the view for a row in my array adapter.

Here's the main activity code, along with the array adapter:

package com.briancsinger.testlist;

import java.net.URL;
import java.util.ArrayList;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class TestList extends ListActivity {

 NewsList newsList = null;
 ArrayList<NewsItem> newsItems;

 //Button btnGetNews;
 ListView listNews;

 ArrayList<String> titles;
 ArrayAdapter<String> aa;
 private NewsItemsAdapter nia;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  /** Create handler to handle XML Tags ( extends DefaultHandler ) */
  XMLHandler myXMLHandler = new XMLHandler();

  /*btnGetNews = (Button)findViewById(R.id.getNews);
  listNews = (ListView)findViewById(R.id.newsList);*/

  //btnGetNews.setOnClickListener(this);

  titles = new ArrayList<String>();
  newsItems = new ArrayList<NewsItem>();
  //aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, titles);

  nia = new NewsItemsAdapter(this, R.layout.row, newsItems, this);
        setListAdapter(nia);

  //listNews.setAdapter(aa);

  try {

   /** Handling XML */
   SAXParserFactory spf = SAXParserFactory.newInstance();
   SAXParser sp = spf.newSAXParser();
   XMLReader xr = sp.getXMLReader();

   /** Send URL to parse XML Tags */
   URL sourceUrl = new URL(
   "http://search.yahooapis.com/NewsSearchService/V1/newsSearch?appid=YahooDemo&amp;query=madonna&amp;results=10&amp;language=en");


   xr.setContentHandler(myXMLHandler);
   xr.parse(new InputSource(sourceUrl.openStream()));

  } catch (Exception e) {
   System.out.println("XML Pasing Excpetion = " + e);
  }

  /** Get result from XMLHandler SitlesList Object */
  newsList = XMLHandler.getNewsList();

  //
  titles.addAll(newsList.getTitle());

  NewsItem item = null;

  for(int i = 0; i < titles.size(); i++) {

   item = new NewsItem();
   item.setTitle(newsList.getTitle().get(i));
   item.setSummary(newsList.getSummary().get(i));
   item.setUrl(newsList.getUrl().get(i));
   item.setClickUrl(newsList.getClickUrl().get(i));
   item.setThumbnail(newsList.getThumbnail().get(i));


   newsItems.add(item);
  }

  nia.notifyDataSetChanged();




  //aa.notifyDataSetChanged();

 }



 private class NewsItemsAdapter extends ArrayAdapter<NewsItem> {

        private ArrayList<NewsItem> items;
        private ImageLoader imageLoader; 
        private Activity activity;

        public NewsItemsAdapter(Context context, int textViewResourceId, ArrayList<NewsItem> items, Activity a) {
                super(context, textViewResourceId, items);
                this.items = items;
                activity = a;
                imageLoader= new ImageLoader(activity.getApplicationContext());
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                View v = convertView;
                if (v == null) {
                    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    v = vi.inflate(R.layout.row, null);
                }
                NewsItem ni = items.get(position);
                if (ni != null) {
                        TextView title = (TextView) v.findViewById(R.id.title);
                        TextView summary = (TextView) v.findViewById(R.id.summary);
                        ImageView image = (ImageView) v.findViewById(R.id.thumbnail);
                        if (title != null) {
                         title.setText(ni.getTitle());                          
                        }
                        if(summary != null){
                         summary.setText(ni.getSummary());
                        }
                        if(image != null && ni.getThumbnail().getUrl().length() > 0){
                         imageLoader.DisplayImage(ni.getThumbnail().getUrl(), activity, image);
                        }
                }
                return v;
        }


 }
/*
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub

 }*/
}