King David was a man who served God, but he was certainly not perfect. How was he like a man after God's own heart?
The first king of Israel was King Saul, who reigned about 3,000 years ago. King Saul did not serve God with his whole heart, and God chose the young shepherd boy David to serve as King when Saul died.
The Bible says God "raised up David to be their king, concerning whom He also testified and said, 'I have found David the son of Jesse, a man after my heart, who will do all My will.'"
So one key is that God says David would do God's will. There are other characteristics of David that exemplified God's heart in many ways. David loved God. He was humble. He worshiped God with all his heart. He was obedient. When he sinned, he repented and turned to God. When he was afflicted, he humbled himself. He had a tender heart for God. When David went into battle, He would inquire of the Lord and seek His face and His will. David devoted huge resources to building a temple for God.
Now David was far from perfect, while God is perfect. But David did seek after God. He wrote many of the Psalms in the Bible, which are largely worship songs to God. Let us ourselves seek to have God's own heart in us and to love Him and seek Him and worship Him!