Solomon made a marriage alliance with Pharaoh of Egypt. He married Pharaoh's daughter and brought her to live in the City of David until he finished building his palace, the Lord's Temple, and the walls surrounding Jerusalem.
The Temple was finished exactly as specified and planned in Solomon's eleventh year, in the eighth month, the month of Bul. So it took him seven years to build the Temple.