I'm currently using (or at least attempting to use) Droidparts ImageFetcher in my application. There is sample code available showing how it works with CursorAdapter but I haven't been able to understand all of it and replicate it with my ArrayAdapter. I think I understand how the InjectDependency stuff works, but if that could either be further explained or not included in the answer, I'd be grateful.
Anyways, my question is, how do I stop my imageViews from loading with the wrong images once they have been recycled? I've tried attaching an ImageHolder as a tag to the view but it hasn't worked and I can't see the logic behind it...
Here's my code:
@Override
public View getView( int position, View view, ViewGroup parent )
{
if( view == null )
{
LayoutInflater inflater = ( LayoutInflater ) m_context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
view = inflater.inflate( m_resourceId, parent, false );
}
TextView titleView = ( TextView ) view.findViewById( R.id.title );
if( titleView != null ) titleView.setText( m_values.get( position ).title );
ImageView imageView = ( ImageView ) view.findViewById( R.id.image );
if( imageView != null )
{
imageView.setImageDrawable( null );
ViewHolder holder = new ViewHolder();
holder.imageView = imageView;
m_imageFetcher = new ImageFetcher( m_context );
m_imageFetcher.attachImage(m_values.get( position ).imageUrl, holder.imageView, null, 10, null);
view.setTag(holder);
}
return view;
}
Any pointer or example would be greatly appreciated, thanks!
I'd recommend you to extends
org.droidparts.adapter.widget.ArrayAdapter
that already contains an instance ofLayoutInflater
.If you do so, here's the code, the logic should be easy to follow:
Also check out it's
setContent(...)
method as an alternative to providing object list in the constructor. And of course make sure that you've declared<uses-permission android:name="android.permission.INTERNET" />
.