Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8884307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:01:53+00:00 2026-06-14T21:01:53+00:00

I have: A WebViewFragment that just displays a WebView for a given URL. A

  • 0

I have:

  1. A WebViewFragment that just displays a WebView for a given URL.
  2. A TabbedWebViewHandler that handles creating tabs that contain WebViewFragments and adding them to the action bar.
  3. A HelpActivity that creates and displays 4 WebViewFragments (for “further information”, “terms and conditions”, “credits” and “purpose of this app” help screens respectively).

All of this works fine, except the first tab is always just a blank black screen when the HelpActivity first starts:

blank Android tab

The other tabs work fine, and the first tab (in this case the “info” tab) will render it’s web view properly if another tab is selected and then the “info” tab is reselected.

I always select the first tab after I’ve created it and added it to the action bar tabs with actionBar.selectTab(newTab);. I know that the code to do this is running, because the log contains “selecting first tab”.

I’m also using the TabbedWebViewHandler for other activities that do the same thing (including for activities that only have one “tab” and so don’t display the tab navigation), so I’d prefer to fix TabbedWebViewHandler instead of putting a workaround in HelpActivity.

I’m using ActionBarSherlock / the Android support library to provide my tab functionality if that’s relevant.

How can I make sure that the first tab of my activity is always displayed properly?

WebViewFragment

public class WebViewFragment extends Fragment {
    private static final String TAG = WebViewFragment.class.getSimpleName();
    private String url;
    @Override
    public View onCreateView(
            LayoutInflater inflater,
            ViewGroup container,
            Bundle savedInstanceState) {
        Log.d(TAG, String.format("onCreateView(): URL is '%s'", url));
        View v = inflater.inflate(R.layout.snippet_webview, container, false);
        WebView wv = (WebView) v.findViewById(R.id.webViewWebView);
        wv.loadUrl(url);
        return v;
    }
    public void setUrl(String url) {
        this.url = url;
    }
}

TabbedWebViewHandler

public class TabbedWebViewHandler {
    private static final String TAG = "TabbedWebViewHandler";
    private final ActionBar actionBar;
    private final Context hostContext;
    private final FragmentManager fragmentManager;
    public TabbedWebViewHandler(SherlockFragmentActivity host) {
        this.hostContext = (Context) host;
        this.actionBar = host.getSupportActionBar();
        this.fragmentManager = host.getSupportFragmentManager();
    }
    public void addTab(String title, String renderUrl) {
        Tab newTab = makeTab(title, renderUrl);
        actionBar.addTab(newTab);
        // FIXME: buggy! tabs don't show on first load
        if (actionBar.getTabCount() == 1) {
            /* first tab: select it by default */
            Log.d(TAG, "Selecting first tab");
            actionBar.selectTab(newTab);
        }
        if (actionBar.getTabCount() > 1) { 
            /* more than one tab: enable navigating between tabs */
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        }
    }
    private Tab makeTab(String title, String renderUrl) {
        WebViewFragment f = 
                (WebViewFragment) 
                    SherlockFragment.instantiate(
                        hostContext, 
                        WebViewFragment.class.getName());
        f.setUrl(renderUrl);
        ActionBar.TabListener l = new WebViewFragmentTabListener(f);
        Tab newTab = actionBar.newTab();
        newTab.setText(title);
        newTab.setTabListener(l);
        return newTab;
    }
    private class WebViewFragmentTabListener implements ActionBar.TabListener {
        private final WebViewFragment fragment;
        public WebViewFragmentTabListener(WebViewFragment f) {
            this.fragment = f;
        }
        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            // replace current fragment with this fragment
            if (ft == null) { 
                fragmentManager
                    .beginTransaction()
                    .replace(android.R.id.content, fragment)
                    .commit();
            } else {
                ft.replace(android.R.id.content, fragment);
            }
        }
        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            ft.remove(fragment);
        }
        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // do nothing
        }
    }
}

HelpActivity

public class HelpActivity extends BaseActivity {
    private static final String TAG = "HelpActivity";
    private static final String FURTHER_URL = 
            "file:///android_asset/further_info.html";
    private static final String DISCLAIMER_URL = 
            "file:///android_asset/terms_and_conditions.html";
    private static final String CREDITS_URL = 
            "file:///android_asset/image_credits.html";
    private static final String PURPOSE_URL = 
            "file:///android_asset/purpose.html";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "onCreate()");
        super.onCreate(savedInstanceState);
        TabbedWebViewHandler twvh = new TabbedWebViewHandler(this);
        twvh.addTab("Info", FURTHER_URL);
        twvh.addTab("Terms", DISCLAIMER_URL);
        twvh.addTab("Credits", CREDITS_URL);
        twvh.addTab("Purpose", PURPOSE_URL);
    }

}

Log output

I/HelpActivity(20038): onCreate()
D/TabbedWebViewHandler(20038): Selecting first tab
D/WebViewFragment(20038): onCreateView(): URL is file:///android_asset/further_info.html
I/webclipboard(20038): clipservice: android.sec.clipboard.ClipboardExManager@41d57ff8
D/WebViewFragment(20038): onCreateView(): URL is file:///android_asset/further_info.html
I/webclipboard(20038): clipservice: android.sec.clipboard.ClipboardExManager@41d57ff8
D/WebViewFragment(20038): onCreateView(): URL is file:///android_asset/further_info.html
I/webclipboard(20038): clipservice: android.sec.clipboard.ClipboardExManager@41d57ff8
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:01:55+00:00Added an answer on June 14, 2026 at 9:01 pm

    Set the navigation mode to ActionBar.NAVIGATION_MODE_TABS before you start adding tabs.

    edit:
    Found it!
    There’s a passage in action bar’s selectTab() method:

    if (getNavigationMode() != NAVIGATION_MODE_TABS) {
        mSavedTabPosition = tab != null ? tab.getPosition() : INVALID_POSITION;
        return;
    }
    

    which basically prevents tab initialization if the bar is not in ActionBar.NAVIGATION_MODE_TABS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WebViewFragment and when trying to get the webview to use, it
Have an issue with executing routines in CodeIgniter. I have a routine that just
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Im using a fragment that is supposed to display a webview. When I try
Have a look at one of my websites: moskah.com The problem is that it
Have a simple contact us XPage created. Have server side validation in place that
In my application, I have three tabs in the Action Bar. Tab A :
Have a photography site that I want to prevent image copying from. How can
Have a network location that shows paths in the 8.3 short format. I need
Have data that has this kind of structure. Will be in ascending order by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.