Code fragment-callback method, usually named onxxx

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.