Skip to content

Android View onTouchListener

OnTouchListener not working ?

If your app is not registering touch events once the Contextual SDK has been integrated, it may be because the OntouchListener is not working. As Android only allows one OnTouchListener, please follow the steps below to ensure the apps native OntouchListener and the Contextual OntouchListener are working properly.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
//Get the instance of our SDK :
// if PZ is greater than 1.6.3 use 
PZCompositeOnClickListener instance =  PZCompositeOnClickListener.getInstance();

// if lower then use 
SHCompositeOnClickListener instance =  SHCompositeOnClickListener.getInstance();

//Add your own OnTouchListener Class and your View: 
instance.addOnClickListener(new MyOnTouchListener(), myView);
//Set OnTouchListener to our instance :
myView.setOnTouchListener(instance);

Enable/Disable Contextual OnTouchListener

Available for Contextual Version equal to or greater than 1.6.3, you can also enable or disable Contextual OnTouchListener. In the following function by passing true it will enable/re-enable the Contextual OnTouchListener, and a false value will completely disable the feature.

1
2
3
4
 PZCompositeOnClickListener.getInstance().enablePZOnTouchListener(
     <Activity>,
     <Boolean>
 );

Still having trouble? See our Source code

Explanation

Contextual uses the OnTouchListener to capture events in your app. These events - including page views or touch events - can then be used in experiments as filters. For example, to target users the third time they enter a view, the OnTouchListener would be required to capture the number of times a user has entered a screen view before that time.


Last update: 2024-01-14