Android - problems animating ActionBar icon from Fragments Android - problems animating ActionBar icon from Fragments android android

Android - problems animating ActionBar icon from Fragments


Never chang menu items somewhere except

onPrepareOtionsMenu(){}

you should something like this.

in your activity:

boolean mIsRefreshing =false;public boolean onPrepareOptionsMenu(Menu menu) {if(mIsRefreshing){        final MenuItem menuItemRefresh = menu.findItem(R.id.menu_refresh);    menuItemRefresh.setActionView(spinnerActionView);}        return true;    }public void setRefreshing(boolean refreshing){mIsRefreshing = refreshing;invalidateOptionsMenu();  //supportInvelidateOptionsMenu()}

So now you can call from your frament

((YourActivity)getActivity()).setRefreshing(true);((YourActivity)getActivity()).setRefreshing(false);


If you are using the same Animation object each time, you may need to reset your animation before attempting to run it again.

Try adding rotation.reset() above your call to startAnimation().


    "I've noticed another weird bug in this area (I'm happy to add this as a separate question, but I'm updating it here in the hope that it will shed some light on my original problem - I believe both are caused by how I have configured my action-bar from my Fragments).       When I first load a fragment I have 1 static refresh icon displayed. If I rotate the screen... another refresh icon appears... when I rotate the screen back, a 3rd refresh icon appears!     Stranger still, clicking the back-button removes each additional icon in turn, before finally (on the 4th click) returning to the previous screen."

I can give Explanation to this ,When ever you change orientation (Potrait<->landscape).

An activity is restarted when the orientation changes. I'm guessing your code isn't saving needed information before this restart occurs. You can stop this default behavior by handling specific configuration changes yourself (ie: orientation change). A good tutorial on doing this is located here: Handling Runtime Changes