0

I have two images as drawables, one for checked, and one for unchecked.

When the user clicks on a button, I want to swap these views in the ImageView. How can I accomplish this?

4

1 回答 1

2

您可以将 的setImageResource方法ImageView与保存当前图像的资源 id 的类变量结合使用:

ImageView iv = (ImageView)findViewById( R.id.my_image_view );

switch( mCurrentImage )
{
    case R.drawable.image1:
        iv.setImageResource( R.drawable.image2 );
        mCurrentImage = R.drawable.image2;
    break;
    case R.drawable.image2:
        iv.setImageResource( R.drawable.image1 );
        mCurrentImage = R.drawable.image1;
    default:
}
于 2013-08-05T17:22:54.333 回答