Below I have copied and pasted the prevention portion of an article on WebMD.
This is the link to the full article, which discusses just what specifically causes ear infections, proper treatment, and when to worry.
http://www.webmd.com/cold-and-flu/ear-infection/ear-infec...
Here's the prevention part of the article:
You may be able to prevent your child from getting middle ear infections by:
Not smoking. Ear infections are more common in children who are around cigarette smoke in the home. Even fumes from tobacco smoke on your hair and clothes can affect the child.
Breast-feeding your baby. There is some evidence that breast-feeding helps reduce the risk of ear infections, especially if ear infections run in your family.
If you bottle-feed your baby, don't let your baby drink a bottle while he or she is lying down.
Washing your hands often. Hand-washing stops infection from spreading by killing germs.
Having your child immunized. Current immunizations don't specifically prevent ear infections. However, they can prevent illnesses, such as Haemophilus influenzae (Hib) and flu (influenza) that may lead to ear infections. Have your child immunized at the ages suggested by national guidelines. For more information, see the topic Immunizations.
Having your child immunized with the pneumococcal conjugate vaccine (PCV) may help reduce the risk of ear infection.
Taking your child to a smaller child care center. Fewer children means less contact with bacteria and viruses. Children in child care settings can easily spread germs to each other. Try to limit the use of any group child care. For more information, see the topic Choosing Child Care.
Not giving your baby a pacifier. Try to wean your child from his or her pacifier before about 6 months of age. Babies who use pacifiers after 12 months of age are more likely to develop ear infections.