Sewing may work, depending on the context, the problem here is that the stitches are quite likely to tear through the foam and may well work loose over time through friction causing the thread to effectively saw through it.
Adhesive may be the most effective solution, this will be easier with something like leather as there is less likelihood of it soaking through to the surface of the fabric. Here something like a latex based contact adhesive should work reasonably well.
For more porous textiles you could look at bonding a lining of something like canvas or calico to the foam first and then stitching into that or using double sided tape or Velcro.
In all cases I would advise doing some tests with small samples to get a feel for how different methods will perform.