The method starting with onxxx is usually called back.
- Generally, active calls do not start with on.
- Various listener listeners receive callbacks when an event occurs. Such as button. onclicklistener. To implement this interface, you need to implement The onclick abstract method. When an onclick event occurs, it will be called.
package android.view;public class View {public interface OnKeyListener {boolean onKey(View v, int keyCode, KeyEvent event);}public interface OnTouchListener {boolean onTouch(View v, MotionEvent event);}public interface OnHoverListener {boolean onHover(View v, MotionEvent event);}public interface OnGenericMotionListener {boolean onGenericMotion(View v, MotionEvent event);}public interface OnLongClickListener {boolean onLongClick(View v);}public interface OnDragListener {boolean onDrag(View v, DragEvent event);}public interface OnFocusChangeListener {void onFocusChange(View v, boolean hasFocus);}public interface OnClickListener {void onClick(View v);}public interface OnCreateContextMenuListener {void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo);}}
- It is a relative concept to not actively call a callback method, because the callback method also requires a local call. This scenario usually meets certain conditions for execution.
Where the implementer calls, There is a type declared by its interface and it is called, such as onlongclick.
public boolean performLongClick() { sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); boolean handled = false; ListenerInfo li = mListenerInfo; if (li != null && li.mOnLongClickListener != null) { handled = li.mOnLongClickListener.onLongClick(View.this); } if (!handled) { handled = showContextMenu(); } if (handled) { performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); } return handled;}
- The class that implements this interface is usually not called proactively.
If a Class A implements the onlongclicklistener interface, Class A should not call onlongclick by itself.