/** * Interface definition for a callback to be invoked when a view is clicked. */ publicinterfaceOnClickListener{ /** * Called when a view has been clicked. * * @param v The view that was clicked. */ void onClick(View v); }
/** * Listener used to dispatch click events. * This field should be made private, * so it is hidden from the SDK. * {@hide} */ public OnClickListener mOnClickListener;
/** * Register a callback to be invoked when this view is * clicked. If this view is not * clickable, it becomes clickable. * * @param l The callback that will run * * @see #setClickable(boolean) */ publicvoid setOnClickListener(@Nullable OnClickListener l) { if (!isClickable()) { setClickable(true); } getListenerInfo().mOnClickListener = l; }
/** * Call this view's OnClickListener, ifitis defined. * Performs all normalactions associated with * clicking: reporting accessibility event, playing * a sound, etc. * * @return True there was an assigned OnClickListener * that was called, false * otherwise is returned. */ public boolean performClick() { final booleanresult; final ListenerInfo li = mListenerInfo; if (li != null && li.mOnClickListener != null) { playSoundEffect(SoundEffectConstants.CLICK); li.mOnClickListener.onClick(this); result = true; } else { result = false; } sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); returnresult; }
/** * Created by zhpan on 2016/7/28. * item中的数据并没有在getView()方法中添加,而是是在item布局文件中添加的。 */ public class MyAdapter extends BaseAdapter { Context mContext; OnNumChangeListener mOnNumChangeListener ;
public void setOnNumChangeListener(OnNumChangeListener onNumChangeListener ){ this.mOnNumChangeListener = onNumChangeListener }