Skip to content
dexafree edited this page Aug 21, 2014 · 2 revisions

This annotation will trigger an event when a View receives or loses focus.

How to use

The method should be this way:

  • public void onFocusChanged(boolean hasFocus)
  • public void onFocusChanged(View v, boolean hasFocus)

Example

@OnFocusChanged(R.id.my_view)
public void onFocusChanged(boolean hasFocus) {
    Toast.makeText(this, "View has focus: $hasFocus", Toast.LENGTH_SHORT).show();
}