I have an alarm symbol on my interface. I want it like if anyone clicks on this then he/she can get another interface. so how to write a click event of Imageview. plz give me answer. Thank you
Using clickable imagesYou can turn any View , such as an ImageView , into a button by adding the android:onClick attribute in the XML layout. The image for the ImageView must already be stored in the drawable folder of your project.
ImageView is used when we want to work with images or we want to display them in our application. So, this article will give you a complete idea of using an ImageView as a Button in android studio. So, without wasting further time let's go to the article and read how we can achieve this task.
To make a View clickable so that users can tap (or click) it, add the android:onClick attribute in the XML layout and specify the click handler. For example, you can make an ImageView act like a simple Button by adding android:onClick to the ImageView . In this task you make the images in your layout clickable.
You can add an OnClickListener
to ImageView
using setOnClickListener
method on your ImageView
and write your code in the listener's onClick
method.
imageView.setOnClickListener(clickListener);
OnClickListener clickListener = new OnClickListener() {
public void onClick(View v) {
if (v.equals(imageView)) {
// Write your awesome code here
}
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With