1

我有一个 ActionBar 可以添加带有片段的选项卡,并且在其中一些选项卡(片段)中有一个列表视图。当我单击其中一个 ListView 项目时,我想隐藏 ActionBar。

这是具有列表视图的选项卡。

   public class FragmentsTab2 extends SherlockListFragment implements
            ActionBar.TabListener {
        private Fragment mFragment;
        String[] values  = { "Consulting&Technology", "Infra-estruturas", "HRO",
                "BPO", "Contact Center"};
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Get the view from fragment1.xml
            getActivity().setContentView(R.layout.fragment2);
        }

        public void onActivityCreated(Bundle savedInstaceState){
            super.onActivityCreated(savedInstaceState);
            setListAdapter(new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,values));

        }

        @Override
        public void onListItemClick(ListView l, View v, int position, long id) {
    //      FragmentManager fm = getFragmentManager();
    //      switch (position)
    //      {
    //      case 0:
    //          newFragment = new FragmentsTec();
    //          break;
    //      }
    //      FragmentTransaction ft = fm.beginTransaction();
    //      ft.addToBackStack(null)
    //      .commit();

                String sText = ((TextView) v).getText().toString();
    //            Intent intent = null;
                if(sText.equals("Consulting&Technology"))
                {
                    mFragment = new FragmentsTec();
                    FragmentTransaction ft = getFragmentManager().beginTransaction(); 
                    ft.replace(android.R.id.content, mFragment);
                    ft.commit();
                }
                else
                if(sText.equals("Infra-estruturas"))
                {
                    mFragment = new FragmentsInfra();
                    FragmentTransaction ft = getFragmentManager().beginTransaction(); 
                    ft.replace(android.R.id.content, mFragment);
                    ft.commit();
                }
                else
                if(sText.equals("HRO"))
                {
                    mFragment = new FragmentsHRO();
                    FragmentTransaction ft = getFragmentManager().beginTransaction(); 
                    ft.replace(android.R.id.content, mFragment);
                    ft.commit();
                }
                else
                if(sText.equals("BPO"))
                {
                    mFragment = new FragmentsBPO();
                    FragmentTransaction ft = getFragmentManager().beginTransaction(); 
                    ft.replace(android.R.id.content, mFragment);
                    ft.commit();
                }
                else
                if(sText.equals("Contact Center"))
                {
                    mFragment = new FragmentsCC();
                    FragmentTransaction ft = getFragmentManager().beginTransaction(); 
                    ft.replace(android.R.id.content, mFragment);
                    ft.commit();
                }
        }

我尝试使用getSupportActionBar.hide(),但由于它是 SherlockListFragment,所以不可能。

更新:我试图声明 actionBar 应该在 ListView 选项卡中消失。它应该在 Fragment 上完成。而且由于我使用的是 SherlockFragment 我必须使用getSherlockActivity()而不是getActivity()

    public class FragmentsCC extends SherlockFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActivity().setContentView(R.layout.fragmentcc);
        ActionBar actionBar = getSherlockActivity().getSupportActionBar();
        actionBar.hide();

    }


}
4

0 回答 0