code: private void adaptButtonVisibility() {
          if (viewPager != null && viewPagerAdapter != null && backButton != null &&
                  nextButton != null && finishButton != null) {
              int selectedIndex = viewPager.getCurrentItem();
              backButton.setVisibility(selectedIndex > 0 ? View.VISIBLE : View.GONE);
              nextButton.setVisibility(
                      selectedIndex < viewPagerAdapter.getCount() - 1 ? View.VISIBLE : View.GONE);
              finishButton.setVisibility(
                      selectedIndex == viewPagerAdapter.getCount() - 1 ? View.VISIBLE : View.GONE);
          }
      }
docs: Adapts the visibility of the dialog's buttons, depending on the currently shown fragment.