Android – listview caching with different color filters does not work

I am using a listview using viewholder mode and gain the advantage of caching mechanism. This is a code fragment. I try to set one of the backgrounds of my list items

if(drawable!=null)
    {
        if(this.backgroundBurnColor!=null && this.backgroundBurnColor.getValue()!=0)
        {
            Log.d("burncolor", this.backgroundBurnColor.getValue()+"");
            drawable.setColorFilter(this.backgroundBurnColor.getValue(), Mode.MULTIPLY);


        }else if(this.burnColorKey!=null)
        {
            Log.d("burncolor", this.Owner.getOwner().getColors().get(this.burnColorKey).getValue()+"");
            drawable.setColorFilter(this.Owner.getOwner().getColors().get(this.burnColorKey).getValue(), Mode.MULTIPLY);
        }else{
            drawable.setColorFilter(null);
        }
        v.setBackgroundDrawable(drawable);
    }

In this code, drawable applies to the same item type, but even if I change the same item type when I can draw an image, it will change as needed. However, changing the drawable color filter will change each drawable filter in the list section that appears on the screen. For example, when I scroll down the list and different color filters appear on the screen, All paintable color filters switch to the same filter. I need to get a separate color filter for each row. Is that helpful? thank you

resolvent:

For those who want to know the answer, Romain guy has a blog post about paintable mutations in Android: http://www.curious-creature.org/2009/05/02/drawable-mutations/

When drawable is referenced from a resource, only one drawable instance is initialized, so all references refer to the same object. Therefore, drawables has a mutate () method

Not writing

 drawable.setColorFilter(null);

writing

 drawable.mutate().setColorFilter(null);

Will solve the problem

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>