2012-10-06 278 views
0

我使用Action Bar Sherlock编写了一个UI。 我完成交换片段(并显示其自己的数据),但是当我的活动创建时,什么都不显示。活动启动时不显示片段

这里我的代码:

public class TabsActivity extends SherlockFragmentActivity{ 
    public static DetailedClinica detailedClinica=null; 

    @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      SimpleClinica clinica = (SimpleClinica) getIntent().getParcelableExtra("clinica"); 
      try { 
       detailedClinica = getDetailedClinica(clinica.getIdClinica().toString()); 
      } catch (InterruptedException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (ExecutionException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

      getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

      ActionBar.Tab newTab0 = getSupportActionBar().newTab(); 
      newTab0.setText("Info"); 
      //fillFirstTab(clinica,newTab0); 


      ActionBar.Tab newTab1 = getSupportActionBar().newTab(); 
      newTab1.setText("Dettagli"); 

      getSupportActionBar().addTab(newTab0); 
      getSupportActionBar().addTab(newTab1); 

      newTab0.setTabListener(new TabListener()); 
      newTab1.setTabListener(new TabListener()); 
    } 

public class TabListener implements ActionBar.TabListener { 

    public void onTabSelected(Tab tab, FragmentTransaction ft) { 
     if (tab.getPosition() == 0){ 
      FragmentClinica fragmentClinica = new FragmentClinica(); 
      ft.replace(android.R.id.content, fragmentClinica); 
     }else{ 
      FragmentDetailed fragmentDetailed = new FragmentDetailed(); 
      ft.replace(android.R.id.content, fragmentDetailed); 
     } 

    } 

    public void onTabUnselected(Tab tab, FragmentTransaction ft) { 
     FragmentClinica arg0 = new FragmentClinica(); 
     ft.detach(arg0); 
    } 

    public void onTabReselected(Tab tab, FragmentTransaction ft) { 
     // TODO Auto-generated method stub 

    } 

其中FragmentClinica是:

public class FragmentClinica extends Fragment { 
    public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved){ 
     return inflater.inflate(R.layout.tab1, group, false); 
    } 

    @Override 
    public void onActivityCreated (Bundle savedInstanceState){ 
     super.onActivityCreated(savedInstanceState); 
     TextView textView = (TextView) getActivity().findViewById(R.id.textView1); 
     textView.setText("Ciao"); 
    } 
} 

建议? 在此先感谢

回答

0

当你做一个FragmentTransaction,你必须提交更改

... 
ft.commit(); 
0

我没有看到任何地方,您设置的选项卡的内容...

也许你需要取消注释以下代码行?

//fillFirstTab(clinica,newTab0); 
+0

不,有些东西出现,就像我说的点击标签。 – FrankBr