OnClick Listener:
@OnClick(R.id.login)
public void login(View view) {
// Additional logic
}
All arguments to the listener method are optional:
@OnClick(R.id.login)
public void login() {
// Additional logic
}
Specific type will be automatically casted:
@OnClick(R.id.submit)
public void sayHi(Button button) {
button.setText("Hello!");
}
Multiple IDs in a single binding for common event handling:
@OnClick({ R.id.door1, R.id.door2, R.id.door3 })
public void pickDoor(DoorView door) {
if (door.hasPrizeBehind()) {
Toast.makeText(this, "You win!", LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Try again", LENGTH_SHORT).show();
}
}
Custom Views can bind to their own listeners by not specifying an ID:
public class CustomButton extends Button {
@OnClick
public void onClick() {
// TODO
}
}