在Sherlock ListFragment中隐藏操作栏

时间:2013-07-02 09:31:31

标签: listview actionbarsherlock fragment

我有一个ActionBar,它添加了带有片段的标签,并且在其中一些标签(片段)中有一个列表视图。当我点击其中一个ListView项目时,我想要隐藏ActionBar。

这是具有Listview的标签。

   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();

    }


}

0 个答案:

没有答案