The following code snippet will help you to pragmatically turn on and turn off wi-fi in android. This sample code is using android Switch (Available from android API level 14) to toggle between wi-fi state.
Read this post on javatechig.com