What causes swimmer's ear, and what's the best treatment?

Bacterial infection. Warm dark wet spaces such as a wet ear canal make an ideal breeding ground for bacteria such as pseudomonas and staph and these cause swimmers ear. Antibiotic / steroid drops are most effective in treating it. It is more common in people who clean their ears with qtips as wax protects the skin from infection. Another reason to not clean your ear canals. Only the very outside should be touched.
Swimmer's ear. It is usually due to a disruption of the normal protective environment of the ear canal (cerumen, sebaceous oil, hair) from swimming, humidity, maceration of the ear skin, dermatitis and local trauma (use of cotton-tipped applicators or other foreign bodies). Avoiding water and acidifying the ear canal are good preventatives. Make sure ear drum is intact before placing any drops in the ear.