There is such a method

public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_progress_show) { progress_menu_item.setActionView(R.layout.menu_item_layout); if(viewPager.getCurrentItem()==1) { frag2.reloadWebView(); // Call method } if(viewPager.getCurrentItem()==2) { frag3.reloadWebView1(); // Call method } new Handler().postDelayed(new Runnable() { @Override public void run() { progress_menu_item.setActionView(null); } }, 5000); return true; } return super.onOptionsItemSelected(item); } 

I want to combine with this

  public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return true; default: return super.onOptionsItemSelected(item); } 

if R.id.home pressed, the finish is performed, and if not, then 1 condition

    1 answer 1

    So?

      public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if(id == android.R.id.home){ finish(); return true; } //noinspection SimplifiableIfStatement else if (id == R.id.action_progress_show) { progress_menu_item.setActionView(R.layout.menu_item_layout); if(viewPager.getCurrentItem()==1) { frag2.reloadWebView(); // Call method } if(viewPager.getCurrentItem()==2) { frag3.reloadWebView1(); // Call method } new Handler().postDelayed(new Runnable() { @Override public void run() { progress_menu_item.setActionView(null); } }, 5000); return true; } return super.onOptionsItemSelected(item); } 
    • thank you, kind - elik