How to detect if user clicks outside of a listview?

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.

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.

1 Like

Hi there, thanks for reply.

Is there any small solution ?

If no, I will try your solution.

Thanks.

No other solution comes into my mind. Thank you.

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

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!

1 Like

hi there, thanks for your reply.

I’ll try it.

Thanks.

Thanks for your replay.

Your solution is also good.

Thanks.