I have an alarm s开发者_如何转开发ymbol 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
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
}
}
};
Faster.
imageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Your code.
}
});
with lambda expression
img_drawer_open_icon.setOnClickListener(v -> Home.drawerLayout.openDrawer(GravityCompat.START));
Also just do it in some easy steps visually: 1- Click your Image 2- From Attribute, Select OnClick and Type a Name Such as onCkick_btnST 3- In code of Your xml, find and select the above verb 4- using yellow bulb menu, select "Create OnClick Event Handler" 5- Fill your Code in created area. The benefit of this methode is that U`LL see that event title in structure tab of Android Studio!
精彩评论