How to detect if user clicks outside of a listview?

How to detect if user clicks outside of a listview?
0.0 0

#1

Hi, I’m working on cocos2dx 3.12 version. I want to close listview if user clicks outside of listview.

How to do it ?

Please help me.
thanks.


#2

You can add the same touch listener to all objects in your scene. And add your listview tag or name. In your touch handler, check the tag or name of the touched object. If it is not your listview’s tag, then outside of your listview is touched.


#3

Hi there, thanks for reply.

Is there any small solution ?

If no, I will try your solution.

Thanks.


#4

No other solution comes into my mind. Thank you.


#5

you have the position for the listview and the contentsize
use something like
if(rect.containsPoint(touch->getLocation))
{
}
else{
}


#6

Use a transparent layer under the listview. Attach a click listener to this layer.

The layer would be a very big button for closing the listview that the user would not see. When you click outside the listview, you will click this layer.

p.d. @bilalmirza method will work too!


#7

hi there, thanks for your reply.

I’ll try it.

Thanks.


#8

Thanks for your replay.

Your solution is also good.

Thanks.