I don't think this works for a ListView when using setBackgroundDrawable(). 
At least I've not gotten it to work when calling mutate() at every point 
possible.

Is there a trick to get this to work?

I didn't load mine from XML, but created it programmatically.  Here are the 
times I called it and it hasn't worked:

1. Right after creation.
2. Right before passing it to setBackgroundDrawable()
3. A few times in between
4. All of the above.

I just went back to doing a drawable for each view in the ListView.

Steven
Studio LFP
http://www.studio-lfp.com


On Monday, October 10, 2011 5:58:11 AM UTC-5, Mark Murphy (a Commons Guy) 
wrote:
>
> On Mon, Oct 10, 2011 at 6:54 AM, dashman <[email protected]> wrote:
> > I've got a ListView and for each item I display a selector image
> > button
> > defined similar to below:
> >
> > <?xml version="1.0" encoding="utf-8"?>
> >  <selector xmlns:android="http://schemas.android.com/apk/res/android";>
> >     <item android:state_pressed="true"
> >           android:drawable="@drawable/flag_clear2" />
> >     <item android:drawable="@drawable/flag_clear1" />
> >  </selector>
> >
> >
> > I thought I could load the drawable from the resource file once and I
> > would assign the drawable to each item in the list.
> >
> > That doesn't work because it seems all the items are sharing the
> > same instance and causes problems. When clicking on one - all
> > of the image buttons hilight.
>
> Sounds like you need to mutate your drawable:
>
> http://android-developers.blogspot.com/2009/05/drawable-mutations.html
>
> -- 
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> Warescription: Three Android Books, Plus Updates, One Low Price!
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to