When He had removed him, He made David their king. In His testimony about him He said, ‘I have found David, son of Jesse, to be a man after My heart, who will carry out all of my wishes.’ Acts 13:22
At the direction of God Saul is appointed king, and at the signal from God Saul is removed as king after a reign of 40 years which includes Samuel as judge. Then, as a boy, David kills enemy Goliath and makes a name for himself as intelligent, outspoken, solidly confident in God, and one who carries through on what he says.
‘I have found David a man after My own Heart,’ God later says (1 Samuel 13:14), and is to be taken with limits lest anyone stumble. When David does rule as king he takes Bathsheba into his chamber and has her husband Uriah quietly killed on the battlefield. David commits both adultery and murder. Though God raises David with the zeal for God, places him in power, sadly David chooses to twice break the 10 Commandments.
David’s temptation to sin shows when he dances naked before God in the great celebration. Some say this is exuberance for the spiritual. More importantly this is a signal to us that his self-interest is built so high, by himself and by others, as he chooses wrong over right. Having sinned, the Prophet Nathan hears David repentant statement to God and tells David he is forgiven. (2 Samuel 12:13) God forgives when we are truly repentant.