Can I do something to prevent gallstones?

Diet. While gallstone formation may be heavily influenced by factors you cannot control (such as heredity), diet remains a major contributor. Gallstones are rare in non-western countries; we believe that our high cholesterol, high fat (esp saturated ones!) diet is the cause. Ironically, rapid weight loss is a risk factor, so slow/steady dieting is best.
Healthy lifestyle. There is no proven way to prevent the formation of gallstones. The best advise would be to eat wisely, including a diet rich in fiber and fruit with fats predominantly rich in polyunsaturated fats; exercise regularly; and keep your weight as stable as possible. Good luck!