我使用 Action Bar Sherlock 编写了一个 UI。我完成了交换片段(并显示自己的数据),但是当我的 Activity 创建时,什么都没有出现。
这是我的代码:
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");
}
}
建议??提前致谢