It seems that onOff
is null.
You are trying to set onOff first which is null and then after few lines trying to set
onOff = (ToggleButton)v.findViewById(R.id.onoff);
move this line up before you try to access onOff.
also if (tgpref = true)
should be if (tgpref == true)