This has long been an issue in Police circles. Officers using a restroom on duty and leaving their service weapon behind when they leave.
One of Hillary's secret service detail got demoted for doing that not long ago.
The best advice is to place your weapon in the "cradle" formed by your pants/underwear when you use the restroom. If for some reason it will not rest there (or you don't want it there) place it muzzle down next to your ankle. The reduces the liklihood that you'll absentmindedly walk off without it.
Note: for women in dresses (or those of you who dress funny, like Kilts) placing the gun in your lap is suggested. Though that can give rise to "fiddling" to while away the time.
If one is wearing a coat or jacket, hanging it on the stall door and placing the gun in the pocket (securely) may work. The caveat here is that in women's restrooms purse snatchers have been known to grab anything on that hook (where women frequently hang their purses) and run off whilst you are "occupied".
If the restroom has a toilet tank behind the seat, place both your car keys and firearm on the tank. This way you cannot drive off without your keys and your gun. If you wear glasses, substitute them for the car keys as long as you can still see fairly well.
When preparing to leave, place the firearm in a suitable safe & stable place until your clothing is arranged, then holster it. Attempting to tuck in a shirt/blouse with the gun pulling on one side of your pants can invite embarrassment or disaster.