我需要三个选项卡,每个选项卡都打开一个不同的网页。我的代码使用 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 ) );
}
}