0

我使用 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");
    }
}

建议??提前致谢

4

2 回答 2

0

When you do a FragmentTransaction, you have to commit the change

...
ft.commit();
于 2012-10-06T11:57:17.757 回答
0

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

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

//fillFirstTab(clinica,newTab0); 
于 2012-10-06T12:06:00.097 回答