java - How to change menu item dynamically/instantly? -


i have refresh button on action bar 3 activities. these 3 activities extended baseactivity. provides me write oncreateoptionsmenu(menu menu) { //... } method once.

when user clicks it, want change icon refreshing icon.

i can handle click , refresh operations , changing icon cannot handle change icon when operation completes.

what best way know when method (which located in activity extends baseactivity) has finished job? have use interface handle on baseactivity's onoptionsitemselected() method?

when want change icon, call invalidateoptionsmenu() (this trigger oncreateoptionsmenu(menu menu) called) , add logic change icon within oncreateoptionsmenu(menu menu) e.g.

@override   public boolean oncreateoptionsmenu(menu menu) {     menuinflater menuinflater = getmenuinflater();     menuinflater.inflate(r.id.menu, menu);     if(isrefreshing()){       menu.finditem(r.id.refresh).seticon(r.drawable.refreshing);     }else{       menu.finditem(r.id.refresh).seticon(r.drawable.refresh);     }   } 

the above code inflate menu resource r.id.menu , change icon depending on result of isrefreshing().


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -