2014-04-03 83 views
0

你好我正在做一個應用程序,基本上我想知道如果我可以隱藏這些選項卡片段切換enter image description here如果您需要任何我的代碼請求,有噸只是爲了片段和標籤和即時消息不知道是什麼被視爲有益的感謝。如何隱藏片段切換器選項卡allways

public class HomeMediaFragment extends Fragment implements 
    ActionBar.TabListener, ViewPager.OnPageChangeListener{ 

ListView list; 

private ViewPager viewPager; 
private MediaFragment mAdapter; 

private ActionBar actionBar; 
// Tab titles 
private String[] tabs = { "The Time the School Almost (Actually) Burned Down", "The time the math exams were almost cancelled", "The Time NT almost didn't get a new School"," The time the old school almost fell down","The Time NT almost got a new pool","The Time We Almost Killed Graffiti","The Time the Exams Almost Got Destroyed","The Time we had a snow day","The Time The School Almost Fell Down", "+2" }; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

    View v = inflater.inflate(R.layout.fragment_media, container, false); 



    viewPager = (ViewPager) v.findViewById(R.id.pager); 
    actionBar = getActivity().getActionBar(); 
    mAdapter = new MediaFragment(getChildFragmentManager()); 

    if(actionBar.getTabCount() > 0){ 
     actionBar.removeAllTabs(); 
    } 
    viewPager.setAdapter(mAdapter); 
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

    // Adding Tabs 
    for (String tab_name : tabs) { 
     actionBar.addTab(actionBar.newTab().setText(tab_name) 
       .setTabListener(this)); 


    } 

    /** 
    * on swiping the viewpager make respective tab selected 
    * */ 
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 

     @Override 
     public void onPageSelected(int position) { 
      // on changing the page 
      // make respected tab selected 
      actionBar.setSelectedNavigationItem(position); 
     } 

     @Override 
     public void onPageScrolled(int arg0, float arg1, int arg2) { 
     } 

     @Override 
     public void onPageScrollStateChanged(int arg0) { 
     } 
    }); 

    return v; 
} 




@Override 
public void onTabSelected(Tab tab, android.app.FragmentTransaction fragmentTransaction) { 

    viewPager.setCurrentItem(tab.getPosition()); 
} 

@Override 
public void onTabUnselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) { 

} 

@Override 
public void onTabReselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) { 

} 

@Override 
public void onDestroyView() { 
    // TODO Auto-generated method stub 
    super.onDestroyView(); 
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); 

} 

@Override 
public void onPageScrolled(int i, float v, int i2) { 

} 

@Override 
public void onPageSelected(int i) { 

} 

@Override 
public void onPageScrollStateChanged(int i) { 

} 
} 
+0

如果您可以發佈您用於設置菜單的代碼,這將會很有幫助。它可能在封閉活動中,而不是片段本身。 – Nickel

+0

其相當長,但我增加了託管活動 – user3381665

回答

1

取出這些行:

actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

    // Adding Tabs 
    for (String tab_name : tabs) { 
     actionBar.addTab(actionBar.newTab().setText(tab_name) 
       .setTabListener(this)); 


    } 

這些:

@Override 
public void onTabUnselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) { 

} 

@Override 
public void onTabReselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) { 

} 

的第一組線是設置您的導航模式下的標籤,這是沒有必要的,如果你」只需切換片段,然後將標籤添加到視圖中。第二個只是在第一部分中從.setTabListener調用的監聽器。

+0

標籤仍然存在,他們仍然工作完美,anythoughts ?? – user3381665

+1

嘗試在您的第一行刪除「implements ActionBar.Tablistener」,並在「actionBar.setSelectedNavigationItem(position);」在你的onPageSelected函數中。 – Nickel

+0

「實現ActionBar.Tablistener」我已經刪除了錯誤「actionBar.setSelectedNavigationItem(position);」不會讓標籤消失 – user3381665

相關問題