VirUs
VirUs

Reputation: 1

tabs in tabhost don't show proper content

An android app I am making using with tabs widget through webview to show webpage inside the application. The app while executing doesn't show proper data. It only shows a html page that I added for a particular tab. But the html page is seen in all the tabs. And the main content is not visible.

http://prntscr.com/vgcoj

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TabHost th = (TabHost) findViewById(R.id.tabhost); 

    WebView home = (WebView) findViewById(R.id.webView1);
    home.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            findViewById(R.id.progressBar1).setVisibility(View.GONE);
            findViewById(R.id.webView1).setVisibility(View.VISIBLE);
        }
    });  
    home.loadUrl("http://udaipurblog.com");
    home.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

    WebView static1 = (WebView) findViewById(R.id.webView2);

    static1.loadUrl("file:///android_asset/1.html");
    static1.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

    WebView webview2 = (WebView) findViewById(R.id.webView3);
    webview2.loadUrl("file:///android_asset/2.html");
    webview2.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);



    th.setup();
    TabSpec homespec = th.newTabSpec("home");
    homespec.setContent(R.id.tab1);
    homespec.setIndicator("Home");
    th.addTab(homespec);

    TabSpec static1spec = th.newTabSpec("static1");
    homespec.setContent(R.id.tab2);
    homespec.setIndicator("Static1");
    th.addTab(homespec);

    TabSpec static2spec = th.newTabSpec("static2");
    homespec.setContent(R.id.tab2);
    homespec.setIndicator("Static2");
    th.addTab(homespec);

Upvotes: 0

Views: 216

Answers (2)

vtuhtan
vtuhtan

Reputation: 1066

You are adding always homespec tab

TabSpec homespec = th.newTabSpec("home");
homespec.setContent(R.id.tab1);
homespec.setIndicator("Home");
th.addTab(homespec);

TabSpec static1spec = th.newTabSpec("static1");
homespec.setContent(R.id.tab2);
homespec.setIndicator("Static1");
th.addTab(homespec);

TabSpec static2spec = th.newTabSpec("static2");
homespec.setContent(R.id.tab2);
homespec.setIndicator("Static2");
th.addTab(homespec);

Upvotes: 1

Talha Mir
Talha Mir

Reputation: 1258

You have used homespec for every tab . Use respective specs for the tabs. Sorry i can't comment due to my reputation .

Upvotes: 2

Related Questions