Drawable disappears when shared between listview and view
I created a listview with drawables say 1,2,3. I created a button whi开发者_开发技巧ch also has drawable 1.
When I click on the listview item with drawable 1, the drawable from the button disappears.
Any ideas?
Your problem may be caused by the fact that drawables are always shared from a constant Drawable
source. If you want to change the characteristics of one of your drawables, you need to call mutate()
on it so that your other drawables sharing the same base are not affected. With acknowledgments to Google:
Drawable star = context.getResources().getDrawable(R.drawable.star);
if (book.isFavorite()) {
star.mutate().setAlpha(255); // opaque
} else {
star. mutate().setAlpha(70); // translucent
}
Here is the page where that came from.
I found the problem: It was in our API.
Basically, drawables cannot be shared. So the drawable was getting added to the ListView and the same drawable was added to a button. The drawable from the listview disappeared.
Hence, I created 2 array lists with the same drawables; I couldn't think of anything else. And now the drawables don't disappear.
精彩评论