To do it properly you'll need to remove the whole roof lining from the car (not just the soft lining, the whole thing), You can do it in the car but may not be as succesful as it keeps trying to droop down while you're trying to stick it back up.
Peel back the section that is coming loose (if you just want to fix that section), spray with contact adhesive (from Bunnings, Supercheap, etc) on BOTH the soft roof lining and the backing panel (not too much that it soaks through), leave until it's tacky both sides then pull the soft lining back over where it needs to go (holding it up over the top, not letting it touch yet) then progressively press the two sections together working towards the outside. It's hard to explain so hopefully that makes sense!