代码正在工作,但问题是当我从设置中打开/关闭 wifi 时,切换没有更新,就像切换按钮显示打开并且 wifi 也打开但是如果我从设置中关闭 wifi,那么这个切换仍然显示如何更新切换? 编辑最终代码 sry 1st 是错字:(
final WifiManager wifi = (WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
IntentFilter iFilter = new IntentFilter();
iFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
//registerReceiver(broadcastReceiver, itFilter);
Intent batteryStatu = getActivity().registerReceiver(null, iFilter);
final Switch wi = (Switch) av.findViewById(R.id.switch1);
wi.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (wi.isChecked())
{
wifi.setWifiEnabled(true);
}
else {
wifi.setWifiEnabled(false);
} ;
}
});