After additional testing, I've confirmed that the mutate() option doesn't allow the use of one Drawable on multiple view under the following conditions unless there is a trick to it that I'm missing.
1. Using a CursorAdapter with a ListView (Using newView and bindView, haven't tried with getView as it would take a rework of code) 2. GradientDrawable created programmatically (the only way you can do it and customize the gradient colors on the fly) 3. GradientDrawable assigned with setBackgroundDrawable() 4. ListView items having different heights and/or widths Maybe the "state" of the drawable doesn't include the height and width of the object, but there isn't really anything that shows what is included in the "state". Seeing that the alpha was included, one would have thought things like size would have also been included. I'd like to go to reusable Drawables as it would simply things, so if anyone has a viable solution, that would be great. Steven Studio LFP http://www.studio-lfp.com On Monday, October 10, 2011 10:53:46 AM UTC-5, Studio LFP wrote: > > 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

