Diverting thoughts of wanting to gamble by doing something else is one thing that can be done to avoid the habit of gambling, but this is not easy because for people who cannot control themselves they will still follow their desire to gamble and for those who are addicted no matter how difficult the situation is they will follow their desire to gamble.
Diverting your thoughts to something different from gambling is not a permanent solution but only a short term solution that you might not be capable of doing someday when the desperate to gamble increase more. What you should be capable of doing is to not gamble at all regardless of not doing anything else. Learn to say no to gambling and train your body to not allow it get to a stage that when ever you see gambling activities going on, you want to participate too. Prevention of addiction can be done by controlling how you gamble for people that are already into gambling. Controlling your gambling schedules will help reduce how long you gamble and how much that you are losing and this can help prevent gambling addiction too.