Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android how to write click event of an ImageView

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

like image 858
Harsha M V Avatar asked May 13 '11 10:05

Harsha M V


People also ask

Can ImageView be clickable?

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.

Can ImageView be a Button?

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.

How do you make an ImageView clickable like a simple button choose one?

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.


1 Answers

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
        }
    }
};
like image 74
Hussain Avatar answered Oct 26 '22 22:10

Hussain