Skip to content
tylertreat edited this page Dec 31, 2012 · 2 revisions

The Bind annotation is used to indicate that the annotated View is to be bound to a callback method for a given event type. This replaces the need to implement an anonymous inner class in your Activity's onCreate method for your event listeners.

The event attribute corresponds to the event type, while callback indicates the name of the method to be invoked. If an Event is not specified, Event.OnClick is used by default.

The callback method should match the normal listener method in terms of its return type and arguments. For example, an onClick callback should be void and take a View as its argument, while an onKey callback must return a boolean and take a View, int, and KeyEvent as its arguments.

Bind Example

public class MyActivity extends InfinitumActivity {

    @InjectView(R.id.my_button)
    @Bind("buttonClicked")
    private Button mMyButton;

    @InjectView(R.id.my_layout)
    @Bind(value = "layoutTouched", event = Event.OnTouch)
    private LinearLayout mMyLayout;

    private void buttonClicked(View view) {
        Toast.makeToast(this, "Button clicked!", Toast.LENGTH_LONG).show();
    }

    private boolean layoutTouched(View v, MotionEvent event) {
        Toast.makeToast(this, "Layout touched!", Toast.LENGTH_LONG).show();
    }

    // ...

}
Clone this wiki locally