Need to edit a file as root, make sure TextEdit isn’t running, then open the Terminal and:
sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit & open -a "TextEdit" /etc/hosts
The first command (line) runs TextEdit as root; the second one tells it to open the file you want to edit. Make your changes and save. After you’re finished be sure to quit TextEdit or it will still keep editing files as root.