Put some fruit in a plastic cup, then put plastic wrap over the top and to make sure that it stays, put a rubber band around it. Poke holes in the plastic wrap with the tip of a paper clip so the bugs can get in there.
I hate those little buggers. First, make sure you don't have any fruit or peels laying on the counter etc. Or in the trash can. I didn't know I had fruit flies the other day in the kitchen trash until I went to empty it; disturbed what was quite a little colony in there!
Any fruit you do have should go in the fridge. Even if it goes in with some flies on it, the cold will kill them and then you can sweep them out later.
There are several methods you can use to trap the flies including; transforming a piece of paper into a funnel shape and placing it in a container with a small amount of apple cider vinegar at the base so as to draw them. However, the best solution is to clean your house and get rid of rotting food so as to destroy their source of food. For more information on the same, please refer to this link http://www.ehow.com/how_2002530_rid-fruit-flies.html.