title: How to get SelectedItemId of BottomNavigationView in android
body: <p>I have implemented  BottomNavigationView in my app. Everything going easy and perfect but there is one problem i.e. on back press I want to get the currently active tab selected but now selected tab does not change when back press. Fragment changes but tab selection does not change. How can I detect the current tab and change the selected tab on back press. I tried a lot of things to do but not able to get selected tab ID.Please help.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>      int i =   getSelectedItem(bottomNavigationView);
      Log.e("TAG", "onCreate:tab "+i );
  
        private int getSelectedItem(BottomNavigationView bottomNavigationView){
      Menu menu = bottomNavigationView.getMenu();
      for (int i=0;i&lt;bottomNavigationView.getMenu().size();i++){
          MenuItem menuItem = menu.getItem(i);
          if (menuItem.isChecked()){
              return menuItem.getItemId();
          }
      }
      return 0;
  }
  </code></pre>