Wednesday, January 30, 2019
This is a nice trick to make your app more interactive. In this article i will show you an ImageView that can change its image resource after it has been clicked.
1. first, make sure you have you imageView class imported and you have an imageView in your layout file.
2. now i will show you the code to change your image resource
This will replace the current image resource of my_image ImageView.
1. first, make sure you have you imageView class imported and you have an imageView in your layout file.
import android.widget.ImageView;
2. now i will show you the code to change your image resource
ImageView my_image = (ImageView) findViewById(R.id.my_image );
my_image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { my_image.setImageResource(R.drawable.my_image_new); } });
This will replace the current image resource of my_image ImageView.