However, what made GOD to call him as the man after His own heart??
I am sure that even though David did mistakes, there must be something in Him, which matches the heart of GOD. His heart might be desired what GOD's heart desires. Let me try to explore few facts in this direction.
Following is the qualities of David, which pleased GOD.
He was not a Hypocrite: GOD hates hypocrites 
What GOD really expects from a sinner or a person who did terrible mistakes? David even though a sinner, his reaction after committed adultery with Bathsheba and had her husband killed to cover up the sin is agreed to GODs eyes. He confessed his sin with a contrite heart .
David was jealous about GOD:
When Goliath abused the GOD of Israelites, David was the only person who came forward by the name of GOD. He trusted GOD and the words of David in this chapter clearly shows how jealous he about GOD. Furthermore, he manifested the same by giving a wise answer to Michal at the time of her abuse .
He was Humble: GOD commanded to be humble 
David was humbled himself before GOD, and GOD appointed king, Saul. David saw himself as a dead DOG, a locust, a lonely sparrow, a snared bird  even though he was a great king, appointed by GOD. GOD loved his humility.
He depended on GOD: GOD wants to be our LORD 
Even though David is capable of making decisions taking action, he depended on GOD every time. . Book of Psalms 23 is one of the Great poems, which reveals how he depended on GOD. In many bitter times David leaned on GOD's promises.
He worshiped GOD always: GOD is looking for the people who worship Him 
David was the lover of GOD, and always he praises him with his instrument, songs and dance . Being a king of Israelite s and the abused by Michal, he never stopped him to worship GOD in the midst by his dance. David worshiped GOD with all of his power, which is acceptable to GOD . That’s why he could boldly say that “seven times a day I praise you” .
David Loved the word of GOD: Jesus do 
If we read Psalms 119, we can clearly understand how much David loved the word of GOD. He acknowledges the importance and value of the scriptures. 
David Loved to Pray: Jesus do 
In many situations, David prayed. His kingship never stopped him to pray. In the tough times and in troubles also in decision making David prayed to GOD 
In addition to the above features, I would like to mention that David respected Gods appointed king even though it was dangerous to his life. He never took a chance to kill King Saul . He was faithful in his work right from the beginning of his stewardship . moreover, Psalms 17:3 says that “Though you probe my heart and examine me at night, though you test me, you will find nothing. David did not hide anything from GOD.
Finally, it was said about David that he was the one who will do the will of GOD . Based on these points, I conclude that all the above qualities of David, which are very much pleasurable to GOD made to call him the man after His own heart.
 Acts 13:22, 1 Sam 13:13-14.  Ps 119:164
 Mathew 23:28  Mt 4:4, 7, 10
 2 Sam 12:13  Ps 119:97, 148, 11
 1 Sam 17:16, 36, 46 and 2 Sam 6:21  Mt 26:36-44
 Mathew 11:29, 5:3  Ps 116:1-2, Ps 145:18, 2 Samuel 7:18, 12:17, 15:31
 1 Sam 24:14, 2 sam9:8; 16:9, Ps 109:23, Ps 84:3, Ps 124:7  1 Sam 24:8, 26:11 2 Sam 1: 14-16
 Acts 2:36  1 Sam 17:14, 20, 34-35
 1 Sam 17:47, 23:11, 30:8, 2 Sam 2:1  Acts 13:22
 John 4:21-24
 Ps 145:1, Ps 63
 Lk 10:27, Deut 6:5