以下情況: 我有TabActivity與例如三個選項卡,TabA,TabB,TabC。Android。如何更改標籤內的活動
TabC的活動(Act_C_1)中有一個按鈕。所以如果用戶點擊該按鈕,另一個活動(Act_C_2)應該出現在TabC中。
我在此先感謝您的任何建議/意見。
穆爾
UPD:
這裏是我的代碼
TabActivity有三個活動:
public class TabScreen extends TabActivity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_menu);
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, SecondActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("tab_1").setIndicator("Tab1",null).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ThirdActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("tab_2").setIndicator("Tab2",null).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, FourthActivity.class);
spec = tabHost.newTabSpec("tab_3").setIndicator("Tab3",null).setContent(intent);
tabHost.addTab(spec);
}
}
活動 'Act_C_1' 或FourthActivity.java:
public class FourthActivity extends Activity implements OnClickListener
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.fourth);
Button BtnWeiter = (Button)findViewById(R.id.BtnWeiter);
BtnWeiter.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
// I also tried to use LocalActivityManager
// TabActivity parentTabActivity = (TabActivity) getParent();
// LocalActivityManager manager = parentTabActivity.getLocalActivityManager();
// manager.destroyActivity("tab_3", true);
// manager.startActivity("tab_3", new Intent(this, FourthActivity.class));
finish();
startActivity(new Intent(this, FourthActivity.class));
}
}
請檢查此鏈接:[安卓:如何擁有TabActivity的一個選項卡下的多個活動(http://gamma-point.com/content/android-how-have-multiple-activities-under -single-tab-tabactivity) – Ian 2011-11-25 04:47:30