Dynamically change Menu items
<p>I have a menu item that allows the user turn gps on and off.In onCreate() the activity checks the status of the gps  and uses the appropriate resources(2 different icons).How do I dynamically update the item icons?I've tried the code below, but i have a lag : the user has to push the item and enter Location and Security settings twice  for the menu to be updated. Thank you.</p>

<pre><code>@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub

         switch (item.getItemId()) {
           case R.id.GPS:
            startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
            LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

            item.setIcon(R.drawable.gps_off);

        } else {
            item.setIcon(R.drawable.gps);
        }

        break;
</code></pre>

<p>}</p>
