+
+ private void moveToNewPage(int pageNumber, ViewPager webViewPager) {
+ // Check to see if the new page has been populated.
+ if (webViewPager.getChildCount() >= pageNumber) { // The new page is ready.
+ // Move to the new page.
+ webViewPager.setCurrentItem(pageNumber);
+ } else { // The new page is not yet ready.
+ // Create a handler.
+ Handler moveToNewPageHandler = new Handler();
+
+ // Create a runnable.
+ Runnable moveToNewPageRunnable = () -> {
+ // Move to the new page.
+ webViewPager.setCurrentItem(pageNumber);
+ };
+
+ // Try again to move to the new page after 50 milliseconds.
+ moveToNewPageHandler.postDelayed(moveToNewPageRunnable, 50);
+ }
+ }