Loneliness has everything to do with being alone. Being misunderstood by those around you is often confused as being alone, however in a very real way people create a condition of loneliness by their mindset so yes, loneliness and certain a frame of mind are closely related.
The condition is deeply rooted in belief, and how much space your beliefs leave for other people to share in your experiences. For instance, your friend said things which you somewhat believe, and in that way you have made space for them and allowed to the same extent the sense of being alone to dissipate.
The behaviors of belief which creates the condition of loneliness and the feeling of being alone because most people misunderstand you are closely related because many times we maintain a requirement that somebody understand us before we make space for them in our lives. Someone who understands others will never feel alone. Loneliness is as common today as the popular suggestion to always look inwardly for answers and, basically, pay more attention to yourself rather than others. The result is mutual isolation and the feeling of loneliness is inevitable.