我正在尝试使用菜单选项更改 wifi 状态,但是我创建的 Toast 都没有发生任何事情
任何提示或想法都会受到好评。这是我的代码:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.string.Menu_mainMenu:
mainMenu();
case R.string.menu_wifi:
wifiStatus();
}
return super.onOptionsItemSelected(item);
}
public void mainMenu(){
Intent inte = new Intent(getApplicationContext(), DataconectActivity.class);
startActivity(inte);
}
public void wifiStatus(){
final WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if(wifi.isWifiEnabled()){
wifi.setWifiEnabled(false);
Toast.makeText(getApplicationContext(), R.string.wifioff, Toast.LENGTH_LONG);
}
else{
wifi.setWifiEnabled(true);
Toast.makeText(getApplicationContext(), R.string.wifion, Toast.LENGTH_LONG);
}
return;
}