Christopher J.H. Wright, on page 380 of Old Testament Ethics for the People of God, states the following about I Samuel 13:14’s claim that David was a man after God’s own heart.
“‘A man after God’s own heart’ probably does not mean ‘someone whom
God was especially fond of’ (a kind of favouritism the English phrase
seems to suggest, but the Bible elsewhere denies, about God), but
rather, someone who will carry out God’s will and purpose (‘heart’ being
the Hebrew for purposeful intentions, not primarily for emotions).”
That interpretation would make sense, in light of Saul’s
disobedience: “But now thy kingdom shall not continue: the LORD hath
sought him a man after his own heart, and the LORD hath commanded him to
be captain over his people, because thou hast not kept that which the
LORD commanded thee” (I Sam. 13:14 KJV).