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?
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?
您可以将 的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:
}