David feels a little awkward since he's living in a nice house made of fine cedar wood, but God's Ark is just roughing it in a tent. He suggests maybe building a temple to the prophet Nathan—and Nathan says David should do what he thinks best.
But that night, God's voice speaks to Nathan and tells him that he actually hasn't had a problem living in a tent all these years. God reminds Nathan that he's never asked any of the former tribal leaders of Israel to build him a temple—and he won't ask David, either.
Instead, God tells Nathan to give this message to David: God is in David's corner, protecting him and helping him do everything he's doing, blessing him.
There will come a time, says God, when he will have a temple built—but, it will be once David has died.
One of David's kids is going to build the temple: he'll be a good king, and won't lose God's favor—but, when he screws up, God will correct him with human violence. Also, David's successors will ultimately endure and rule forever.
Nathan successfully relays all this info to David.
David says a prayer of thanks to God. He expresses humility, saying that for God to elevate David's house was really impressive and overwhelming—yet at the same time, a "small thing", since God is still so much greater than kings. He hopes the people learn from the example.
He praises God, saying that there's no one like him, and asks God if there's any other nation on earth that can compare to Israel. He also asks God to make sure that he (God) fulfills his promises towards Israel—keeping his people as his own forever, and exalting them.
David concludes his prayer by asking God for a blessing, so that his (David's) house will last forever.