How to Listen to Others Without Being Swayed by Them

Listening to someone to understand them does not mean we have to accept their views or follow their perspectives. We listen to people to learn from them to understand and help them. If we do not know them well, we cannot help them. How can we listen to people who believe differently from us but not allow them to convince us of their views or follow their ideology?