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");
}
}
建議? 在此先感謝
不,有些東西出現,就像我說的點擊標籤。 – FrankBr