public class SampleTabActivity extends TabActivity implements OnClickListener{static TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
//this is SampleTabActivity.java file
intent = new Intent().setClass(this, TabOne.class);
spec = tabHost.newTabSpec("tabOne");
spec.setContent(intent);
spec.setIndicator("Tab One");
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 40;
LinearLayout ll = (LinearLayout) tabHost.getChildAt(0);
android.widget.TabWidget tw = (android.widget.TabWidget) ll.getChildAt(0);
RelativeLayout rllf = (RelativeLayout) tw.getChildAt(0);
TextView lf = (TextView) rllf.getChildAt(1);
lf.setTextSize(20);
intent = new Intent().setClass(this, TabTwo.class);
spec = tabHost.newTabSpec("tabTwo");
spec.setContent(intent);
spec.setIndicator("Tab Two");
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 40;
RelativeLayout rlrf = (RelativeLayout) tw.getChildAt(1);
TextView rf = (TextView) rlrf.getChildAt(1);
rf.setTextSize(20);
intent = new Intent().setClass(this, TabThree.class);
spec = tabHost.newTabSpec("tabThree");
spec.setContent(intent);
spec.setIndicator("Tab Three");
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 40;
RelativeLayout rlrp = (RelativeLayout) tw.getChildAt(2);
TextView rp = (TextView) rlrp.getChildAt(1);
rp.setTextSize(20);
tabHost.setCurrentTab(0);
}}
public class TabOne extends ActivityGroup implements OnClickListener{ @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabone);
TextView tv = new TextView(this);
tv.setText("This is tab One");
//this is TabOne.java file
Button button = (Button)findViewById(R.id.button1);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent = new Intent(this, TabTwo.class);
replaceContentView("TabTwo", intent);
setTab(1);
}
public void replaceContentView(String id, Intent newIntent) {
View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
this.setContentView(view);
}
public void setTab(int index){
SampleTabActivityActivity ParentActivity;
ParentActivity = (SampleTabActivityActivity) this.getParent();
ParentActivity.getTabHost().setCurrentTab(index);
} }
public class TabTwo extends ActivityGroup implements OnClickListener{@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("This is tab Two");
setContentView(tv);
}}
public class TabThree extends ActivityGroup implements OnClickListener{@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("This is tab Three");
setContentView(R.layout.tabone);
}}
在這裏,當我點擊繼續塔博恩按鈕...它去標籤Two..and顯示文本「這是標籤兩個」 ....但我當通過點擊塔博恩選擇塔博恩......內容丟失......Android-標籤內容丟失
我不能再看到繼續按鈕......相反,我看到「這是標籤兩個」 ......
請檢查代碼。 請一些人幫忙......需要做什麼......我要去哪裏錯......?
哪個代碼寫在onResume ... 哪個文件...?哪些代碼? – prathameshr 2012-02-14 11:11:22
你在onCreate()裏面的邏輯也需要在onResume裏面進行所有的活動。 – kosa 2012-02-14 15:10:25