1

in my app I have a refresh button. clicking on it it rotates (animation) while the fragment is updating. suppose I navigate from the given fragment to another and then back. Is there any possibility when I navigate back the refresh Menu Item being clicked automatically without pressing on it.

menu item onclick method

public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.action_refresh:

            item.setActionView(getAnimation());

            getCurrency(code,item);
            mViewpager.setVisibility(View.INVISIBLE);
            Log.i("TAG", "refresh pressed =>");
            return true;
        }

        // Handle your other action bar items...

        return super.onOptionsItemSelected(item);
    }

I want this code to execute when navigating back without pressing the menu Item

Anders Abel
  • 67,989
  • 17
  • 150
  • 217

1 Answers1

1

Yes, you can execute all the actions your are doing when the optionMenu creation method starting from the animation and the real updating as following:

@Override
public boolean onCreateOptionsMenu(Menu menu){

     MenuInflater inflater = getMenuInflater();
     inflater.inflate(R.menu.my_options_menu, menu);

     //Perform the updating action 
     item.setActionView(getAnimation());

        getCurrency(code,item);
        mViewpager.setVisibility(View.INVISIBLE);
        Log.i("TAG", "refresh pressed =>");
        super.onOptionsItemSelected(item);

      return true;
} 
Sami Eltamawy
  • 9,874
  • 8
  • 48
  • 66