I need to track an event each time user clicks on any clickable view in my app. I want to do this generally so e.g. in my main activity.
I know I can override onUserInteraction()
or dispatchTouchEvent()
but these are running even for the clicks which are not clickable views.
I don't need to differ between clickable views, just the fact it is clickable is enough.
In an ideal case, I would also differentiate the Up button from other clicks.
Is this possible?
Distribute your app to testersSelect your Firebase project when prompted. On the Releases page, select the app you want to distribute from the drop-down menu. Drag your app's APK file to the console to upload it. When the upload completes, specify the tester groups and individual testers you want to receive the build.
Google Find My Device is a free app that allows you to trace your phone. You can track any device on your Android phone with this software.
In my opinion, there's no flawless implementation for what you want to achieve.
One possible way is using a OnClickListener wrapper. This needs you or your team to enforce using this wrapper on any clickable views' OnClickListener. But you cannot cover the views in third party library.
public class OnClickListenerWrapper implements OnClickListener {
private OnClickListener listener
public OnClickListenerWrapper (OnClickListener listener) {
this.listener = listener;
}
public void onClick(View view) {
// Logic of tracking
listener.onClick(view);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With