The only way negativity can come into your mind is if you let it in. You have choice whether to let it occupy your mind or not. Do not allow it to cloud your mind.
When someone says something negative to you, it is easy to let it seep into your mind. As soon as you realize what is happening find something else to focus on; read a book, take a walk, talk to a friend… find something else to occupy that private sanctuary.