Reputation: 1200
I'm trying to change the wifi status with a menu option, but nothing happnes either the Toast I've created to advert that the wifi was turned on or of.also, I looked in this other post, but nothing
any hints or ideas will be good received. Here is my code:
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;
}
Upvotes: 0
Views: 96
Reputation: 30168
So ... you're missing the .show()
for the Toast:
Toast.makeText(getApplicationContext(), R.string.wifion, Toast.LENGTH_LONG).show();
Upvotes: 1
Reputation: 3030
I'm guessing that you checked that R.string.menu_wifi really is connected to the right menu item? As far as I can tell, if you don't get the toasts, you dont even get into the wifiStatus method.
edit: Shouldn't you be gunning for R.id.wifi_item?
Upvotes: 0