getView is called several times for the first position in GridView
<p>I have an adapter with this getView:</p>

<pre><code>public View getView(int position, View convertView, ViewGroup parent) {
    Log.d("getView gv", position+"");

    NewsLine holder = null;

    if (convertView == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        convertView = inflater.inflate(R.layout.grid_entry, parent, false);
        holder = new NewsLine();

        holder.iv= (ImageView) convertView.findViewById(R.id.photo);

        convertView.setTag(holder);
    } else {
        holder = (NewsLine) convertView.getTag();
    }

    NewsItem item=news.ITEMS.get(position);
    //---------

    if(item.imgurl!=null &amp;&amp; item.imgurl.compareToIgnoreCase("null")!=0) 
    {
        holder.iv.setVisibility(View.VISIBLE);     
        mMemoryCache.loadBitmap(item.imgurl, holder.iv,position);
    }
    else
        holder.iv.setVisibility(View.INVISIBLE);
    //-------------




    return convertView;
}
</code></pre>

<p>I have two problems:</p>

<ol>
<li><p>the getView is called several times for position 0 (the bitmap is downloaded with an AsyncTask if its missed in a LruCache). I have an animation (alpha from 0-1) that restarts several times for that position.</p></li>
<li><p>because I'm recycling the view sometimes you can see the old imageView content for a fraction of a second.</p></li>
</ol>

<p>//----</p>

<p>And here is the cache class (only heap):</p>

<pre><code>public class SetImgAT extends LruCache&lt;String, Bitmap&gt; {
private static SetImgAT instance;   
private Animation FadeInAnimation;

private SetImgAT(int size, Context context) {
    super(size);
    FadeInAnimation = AnimationUtils.loadAnimation(context, R.anim.fadein);
}

public static synchronized SetImgAT getInstance(int size, Context context) {
    if (instance == null) {
        instance = new SetImgAT(size, context);
    }
    return instance;
}

@Override
protected int sizeOf(String key, Bitmap value) {
    return (value.getRowBytes() * value.getHeight());
}

public void loadBitmap(String url, ImageView imageView,int pos) {
    Bitmap bitmap = instance.get(url.hashCode() + "");
    if (bitmap != null) {
        Log.d("ImageCache", "hit - "+url.hashCode()+"pos:"+pos);
        imageView.setImageBitmap(bitmap);

        imageView.invalidate();
    } else {
        Log.d("ImageCache", "miss");
        BitmapWorkerTask task = new BitmapWorkerTask(imageView);
        task.execute(url);
    }
}

class BitmapWorkerTask extends AsyncTask&lt;String, Void, Bitmap&gt; {
    ImageView mImageView;

    public BitmapWorkerTask(ImageView imageView) {
        mImageView = imageView;
    }

    @Override
    protected Bitmap doInBackground(String... url) {
        Bitmap Picture = null;


        if (url[0] != null &amp;&amp; url[0].compareToIgnoreCase("null") != 0) {
            Log.d("GetBMP from", url[0]);

            URL img_value = null;
            try {
                img_value = new URL(url[0]);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            try {
                Picture = BitmapFactory.decodeStream(img_value
                        .openConnection().getInputStream());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (Picture == null) {
                Log.d("deb", "no bitmap");
            } else {
                Log.d("got deb", "got bitmap to "+url[0].hashCode());                   
                instance.put(url[0].hashCode()+"", Picture);
            }

        }
        return Picture;
    }

    @Override
    protected void onPostExecute(Bitmap result) {
        // super.onPostExecute(result);
        if (result != null) {
            Log.d("deb", "set bitmap");
            mImageView.setImageBitmap(result);
            //mImageView.startAnimation(FadeInAnimation);
        }

    }
}
</code></pre>

<p>//----------------</p>

<p>}</p>

<p>Thank you! :)</p>
