这看起来很简单,但它只是行不通。ImageView 应在选中时更改位图,但始终显示未选中的图像:
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 });
}