我使用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");
}
}
建议?? 提前致谢
答案 0 :(得分:0)
当您执行FragmentTransaction
时,您必须提交更改
...
ft.commit();
答案 1 :(得分:0)
我没有看到你设置标签内容的任何地方......
也许您需要取消注释以下代码行?
//fillFirstTab(clinica,newTab0);