public class CustomView extends View(){ OnCustomEventListener mListener; : :
Create an interface that will be implemented by your activity:
public interface OnCustomEventListener { void onEvent(); } public void setCustomEventListener(OnCustomEventListener eventListener) { mListener = eventListener; }
Now you need to know when the event really happens. For example, when the user touches a point on the screen, override the onTouchEvent method:
onTouchEvent(MotionEvent ev) { if (ev.getAction==MotionEvent.ACTION_DOWN) { if(mListener!=null) mListener.onEvent(); } }
Similarly, you can create the specific event that you want. (examples can touch, wait exactly 2 seconds and let go - you will need to do some logic inside the touch event).
In your activity, you can use the customView object to set the eventListener as such:
customView.setCustomEventListener(new OnCustomEventListener() { public void onEvent() {
rDroid Nov 28 '11 at 8:20 2011-11-28 08:20
source share