简体   繁体   中英

action bar Menu Item

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

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;
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM