I’m writing an API for Android and I need to know when the developer using the API calls View.setOnClickListener() and View.setOnFocusChangeListener(). I don’t want to override either because that would mean to extend View and I don’t want to force the developer to use my subclass -basically because he wouldn’t be able to use the Android GUI editor for Eclipse-.
I tried to override Activity.dispatchTouchEvent() but then I cannot capture movements done with keypad/virtual keyboard.
Any ideas or guidelines on how to do this?
I found that using both
Activity.dispatchTouchEvent()andActivity.dispatchKeyEvent()is the only way of doing this. You have to keep track of the view that had focus previously (so you can know whenonFocusChange()is triggered). TheonClick()can be detected usingMotionEventaction and the view ID.