Reputation: 504
This seems so simple, but it is just not working. The ImageView should change bitmaps when it is checked, but instead it always shows the unchecked image:
public void addImage()
{
ImageView imageView = new ImageView(context);
m_draw = new StateListDrawable();
m_draw.addState(android.util.StateSet.WILD_CARD, m_bitmapUnchecked);
m_draw.addState(new int[] { android.R.attr.state_checked }, m_bitmapChecked);
imageView.setImageDrawable(m_draw);
this.addView(imageView);
}
public void onClick(View v)
{
m_draw.setState(new int[] { android.R.attr.state_checked });
}
Upvotes: 2
Views: 922
Reputation: 5131
The first matching state is the one which will be set. You should put WILD_CARD as the last state.
Upvotes: 3