在我的活动中,我有一个TabHost
.
我有 3 个标签和 3 个活动供他们使用。单击选项卡时如何启动相应的活动?
目前这三个活动都开始了……
如果我运行此代码,每个活动 ( connected_upload
, connected_download
, connected_search
) 都会运行 " onCreate
" 方法。
如何手动启动这些活动?我的意思是我只想在单击相应的选项卡时才开始活动......
public class connected extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.connected);
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
intent = new Intent().setClass(this, connected_upload.class);
spec = tabHost.newTabSpec("Hoch").setIndicator("Hoch",res.getDrawable(R.drawable.freeftp)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, connected_download.class);
String str_path = getIntent().getStringExtra("path");
String str_profil = getIntent().getStringExtra("profil");
String str_server = getIntent().getStringExtra("server");
String str_port = getIntent().getStringExtra("port");
String str_user = getIntent().getStringExtra("user");
String str_password = getIntent().getStringExtra("pw");
intent.putExtra("path", str_path);
intent.putExtra("profil", str_profil);
intent.putExtra("server", str_server);
intent.putExtra("port", str_port);
intent.putExtra("user", str_user);
intent.putExtra("pw", str_password);
spec = tabHost.newTabSpec("Herunter").setIndicator("Herunter",res.getDrawable(R.drawable.freeftp)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, connected_search.class);
spec = tabHost.newTabSpec("Search").setIndicator("Search",res.getDrawable(R.drawable.freeftp)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
//Button Connect Server
Button cmd_mainsite = (Button)findViewById(R.id.but_connected_mainsite);
cmd_mainsite.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
finish();
Intent Intent_mainsite = new Intent(connected.this, Login.class);
startActivity(Intent_mainsite);
}
});
}
}