1 public void handler(int index){
2 fragmentTransaction = fragmentManager.beginTransaction();
3
4 switch (index) {
5 case 1:
6 //如果tabFragment1为空,说明还没创建Tab1
7 if(tabFragment1==null){
8 tabFragment1 = new TabFragment1();
9 }
10 //如果isAdded == true 表示 tab1 已加入布局中
11 if(!tabFragment1.isAdded()){
12 fragmentTransaction.add(R.id.content,tabFragment1);
13 }
14 else{
15 //如果tab2不为空,把tab2隐藏就是、
16 if(tabFragment2!=null){
17 fragmentTransaction.hide(tabFragment2);
18 }
19 //Log.v("rush_yu", "hh");
20 //显示tab1
21 fragmentTransaction.show(tabFragment1);
22 }
23 break;
24 case 2:
25 //如果tabFragment2为空,说明还没创建Tab2
26 if(tabFragment2==null){
27 tabFragment2 = new TabFragment2();
28 }
29 //如果isAdded == true 表示 tab2 已加入布局中
30 if(!tabFragment2.isAdded()){
31 fragmentTransaction.add(R.id.content,tabFragment2);
32 }
33 else{
34 //如果tab2不为空,把tab1隐藏就是、
35 if(tabFragment1!=null){
36 fragmentTransaction.hide(tabFragment1);
37 }
38 //显示tab2
39 fragmentTransaction.show(tabFragment2);
40 //Log.v("rush_yu", "hh1");
41 }
42 break;
43
44 default:
45 break;
46 }
47 fragmentTransaction.commit();
48 }
49 }1