2013-03-19 56 views
1

我想創建一個由兩個選項卡每個進行操作自己的WebView的應用程序。我可以創建標籤,但無法管理他們的網頁瀏覽。要創建「兩個選項卡設有2個獨立的WebView」

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Resources res = getResources(); // Resource object to get Drawables 
    TabHost tabHost = getTabHost(); // The activity TabHost 
    TabHost.TabSpec spec; // Resusable TabSpec for each tab 
    Intent intent; // Reusable Intent for each tab 

    // Create an Intent to launch an Activity for the tab (to be reused) 
    intent = new Intent().setClass(this, fbActivity.class); 

    // Initialize a TabSpec for each tab and add it to the TabHost 
    spec = tabHost.newTabSpec("fb").setIndicator("fb", 
         res.getDrawable(R.drawable.ic_tab_fb)) 
        .setContent(intent); 
    tabHost.addTab(spec); 

    // Do the same for the other tabs 
    intent = new Intent().setClass(this, google.class); 
    spec = tabHost.newTabSpec("google").setIndicator("google", 
         res.getDrawable(R.drawable.ic_tab_google)) 
        .setContent(intent); 
    tabHost.addTab(spec); 


    tabHost.setCurrentTab(0); 
} 
+0

你會得到什麼作爲輸出輸入所有三類... – 2013-03-19 10:30:36

+0

你的代碼是正確的。你得到什麼輸出 – 2013-03-19 10:32:54

+0

我有標籤的輸出,但它沒有顯示我的網頁視圖... – Gaurav 2013-03-19 12:22:46

回答

2

首先創建tabactivity類

public class tabviews extends TabActivity { 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.tab); 
    TabHost tab = getTabHost(); 

    TabSpec tab1 = (TabSpec) tab.newTabSpec("tb1"); 
    TabSpec tab2 = (TabSpec) tab.newTabSpec("tb2"); 


    tab1.setIndicator("Customer", null).setContent(
      new Intent(this, webview1.class)); 
    tab2.setIndicator("Item", null).setContent(
      new Intent(this, webview2.class)); 

    tab.addTab(tab1); 
    tab.addTab(tab2); 



} 

}

創建兩個活動類說webview1.class和webview2.class

public class webview1 extends Activity 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.settings); 
    WebView v = (WebView) findViewById(R.id.webView1); 
    v.loadUrl("http://www.google.com"); 

然後創建具有相同的代碼另一個類。在manifest.xml中

相關問題