His prayer is invalidated, but if he did not intend to respond and only wanted to indicate that he is in prayer, then it is not invalidated. As narrated by Jabir, may Allah be pleased with him: 'The Messenger of Allah, peace and blessings be upon him, sent me while he was heading to Banu al-Mustaliq. I came to him while he was praying on his camel, and I spoke to him. He gestured to me with his hand like this, then I spoke to him again, and he gestured to me like this, and I heard him reciting while nodding his head. When he finished, he said: What did you do regarding what I sent you for? Nothing prevented me from speaking to you except that I was praying.' (Sahih Muslim 1: 383). See: Durar al-Hukkam 1: 102, and Fath Bab al-Inayah 1: 303.