I have a Brompton and although there is a mechanism to stop it from unfolding, the top part of the handlebar is not fixed very firmly so it can detach when I bump against something and then it swings outward.
I use a short bungee cord with hooks on both ends. It's a matter of seconds to put it around the handle bar and hook it into the pedal on the other side.
Without seeing your bike it's hard to know if this would work. Think through how the folding mechanism works, possibly there's only one part that you have to secure, and then find a bungee cord of precisely the correct length so you don't have to wrap it around in some complicated way but just quickly hook it into something.