0

我需要三个选项卡,每个选项卡都打开一个不同的网页。我的代码使用 tabhost 和三个单独的活动。该应用程序第一次运行,但网页无法在第二次试用时打开。我怎样才能解决这个问题?

MyTabActivity.java

public class MyTabActivity extends TabActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TabHost tabHost = getTabHost();

    tabHost.addTab(tabHost
            .newTabSpec("tab1")
            .setIndicator("Tab1",
                    getResources().getDrawable(R.drawable.home))
            .setContent(new Intent(this, Tab1Activity.class)));

    tabHost.addTab(tabHost
            .newTabSpec("tab2")
            .setIndicator("Tab2",
                    getResources().getDrawable(R.drawable.invoice))
            .setContent(new Intent(this, Tab2Activity.class)));

    tabHost.addTab(tabHost
            .newTabSpec("tab3")
            .setIndicator("Tab3",
                    getResources().getDrawable(R.drawable.products))
            .setContent(new Intent(this, Tab3Activity.class)));
    tabHost.setCurrentTab(0);
    }
 }

Tab1Activity.java

 public class Tab1Activity extends Activity {
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Uri uri = Uri.parse( "http://www.yahoo.com" );
    startActivity( new Intent( Intent.ACTION_VIEW, uri ) );
  }
}
4

2 回答 2

1

由于您拥有所有单独的活动,因此您也可以使用 TabActivity 来实现它。

在 TabHost 中使用启动意图

intent= new Intent().setClass(this, yourFirstactivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
于 2013-01-30T06:55:24.877 回答
0

TabActivity has been deprecated in API Level 13. A more modern way to achieve what you are trying to do would be using ActionBar navigation tabs. Use a WebViewFragment for each web page tab.

于 2013-01-30T06:09:42.203 回答