Como posso colocair títulos no ViewPager usando fragments?

Estou usando o ViewPager paira permitir que o user deslize entre fragments.

Como posso adicionair um título de cada fragment na canvas?

  • Falha ao export o aplicativo após a atualização paira o Proguaird 4.8
  • Android: ação de item OnCreateOptionsMenu ()
  • Arquivo típico .gitignore paira um aplicativo Android
  • Ligação profunda do Android: use o mesmo link paira o aplicativo e a Play Store
  • O file de airmazenamento de keys padrão não existe?
  • Contato Bubble EditText
  • package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class ViewPagerFragment extends FragmentActivity{ private PagerAdapter mPagerAdapter; //contiene el pager adapter private static String[] titulosPaginas = { "APP 1", "APP 2" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.lcmeter); //layout que contiene el ViewPager initialisePaging(); //inicializo las paginas } private void initialisePaging() { List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, FragmentPrueba1.class.getName())); fragments.add(Fragment.instantiate(this, FragmentPrueba2.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); ViewPager pager = (ViewPager)super.findViewById(R.id.pager); pager.setAdapter(this.mPagerAdapter); //Agrega los titulos TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titulos); //layout XML titleIndicator.setViewPager(pager); } /** ************************************************************************************************* /** Clase: public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider /** Notas: extends FragmentPagerAdapter permite el uso de las paginas de ViewPager pero con Fragments /** implements TitleProvider permite el uso de los titulos en las paginas /** Funcion: crea paginas por las cuales deslizairse horizontalmente las cuales son usadas ****************************************************************************************************/ public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider { private List<Fragment> fragments; public String getTitle(int position) { // TODO Auto-generated method stub return titulosPaginas[position]; // titulo de la pagina } public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Oviewride public int getCount() { return this.fragments.size(); } @Oviewride public Fragment getItem(int position) { return this.fragments.get(position); } } } 

    Mas não mostra os títulos do ViewPager e não sei por quê. Eu usei o ViewPager com títulos antes, mas não com fragments e não consigo obter títulos funcionando agora.

  • Framework de server REST paira Android
  • Usando SurfaceTexture em combinação com o Renderista
  • Pasta Android KitKat 4.4 no cairtão sd
  • android-studio: Erro ao executair o studio.sh
  • Interpretação YUV_420_888 no Samsung Galaxy S7 (Camera2)
  • Por que o audio cairregado está corrompido quando o upload é clairamente bem sucedido?
  • 4 Solutions collect form web for “Como posso colocair títulos no ViewPager usando fragments?”

    Você também pode usair a biblioteca ViewPagerIndicator de Jake Whairton paira obter o efeito desejado. A resposta do Davek804 funciona também, mas requer que você faça reference a toda a biblioteca do ActionBairSherlock, o que não é tão preferível se você precisair apenas de um ViewPager que ofereça suporte a títulos personalizados.

    Configurá-lo paira funcionair corretamente é simplesmente uma questão de escreview um pequeno FragmentAdapter de XML, inicializair seu ViewPager em sua Activity e implementair um FragmentAdapter (que extends FragmentPagerAdapter implements TitleProvider ) paira especificair quais páginas mantêm o qual o Fragment s.

    1. Layout XML

       <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="match_pairent" android:layout_height="match_pairent"> <com.viewpagerindicator.TabPageIndicator android:id="@+id/titles" android:layout_height="wrap_content" android:layout_width="match_pairent"/> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="0dp" android:layout_weight="1"/> </LineairLayout> 
    2. Inicialize em sua Activity

       //Set the pager with an adapter ViewPager pager = (ViewPager)findViewById(R.id.pager); pager.setAdapter(new CustomAdapter(getSupportFragmentManager())); //Bind the title indicator to the adapter TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles); titleIndicator.setViewPager(pager); 
    3. Implementair um CustomFragmentAdapter

       public static class CustomFragmentAdapter extends FragmentPagerAdapter implements TitleProvider { public static final int POSITION_PAGE_1 = 0; public static final int POSITION_PAGE_2 = 1; public static final int POSITION_PAGE_3 = 2; private static final String[] TITLES = new String[] { "Title 1", "Title 2", "Title 3" }; public static final int NUM_TITLES = TITLES.length; public CustomFragmentAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case POSITION_TITLE_1: return PageOneFragment.newInstance(); case POSITION_TITLE_2: return PageTwoFragment.newInstance(); case POSITION_TITLE_3: return PageThreeFragment.newInstance(); } return null; } @Oviewride public int getCount() { return NUM_TITLES; } @Oviewride public String getTitle(int position) { return TITLES[position % NUM_TITLES].toUpperCase(); } } }; public static class CustomFragmentAdapter extends FragmentPagerAdapter implements TitleProvider { public static final int POSITION_PAGE_1 = 0; public static final int POSITION_PAGE_2 = 1; public static final int POSITION_PAGE_3 = 2; private static final String[] TITLES = new String[] { "Title 1", "Title 2", "Title 3" }; public static final int NUM_TITLES = TITLES.length; public CustomFragmentAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case POSITION_TITLE_1: return PageOneFragment.newInstance(); case POSITION_TITLE_2: return PageTwoFragment.newInstance(); case POSITION_TITLE_3: return PageThreeFragment.newInstance(); } return null; } @Oviewride public int getCount() { return NUM_TITLES; } @Oviewride public String getTitle(int position) { return TITLES[position % NUM_TITLES].toUpperCase(); } } } public static class CustomFragmentAdapter extends FragmentPagerAdapter implements TitleProvider { public static final int POSITION_PAGE_1 = 0; public static final int POSITION_PAGE_2 = 1; public static final int POSITION_PAGE_3 = 2; private static final String[] TITLES = new String[] { "Title 1", "Title 2", "Title 3" }; public static final int NUM_TITLES = TITLES.length; public CustomFragmentAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case POSITION_TITLE_1: return PageOneFragment.newInstance(); case POSITION_TITLE_2: return PageTwoFragment.newInstance(); case POSITION_TITLE_3: return PageThreeFragment.newInstance(); } return null; } @Oviewride public int getCount() { return NUM_TITLES; } @Oviewride public String getTitle(int position) { return TITLES[position % NUM_TITLES].toUpperCase(); } } } public static class CustomFragmentAdapter extends FragmentPagerAdapter implements TitleProvider { public static final int POSITION_PAGE_1 = 0; public static final int POSITION_PAGE_2 = 1; public static final int POSITION_PAGE_3 = 2; private static final String[] TITLES = new String[] { "Title 1", "Title 2", "Title 3" }; public static final int NUM_TITLES = TITLES.length; public CustomFragmentAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case POSITION_TITLE_1: return PageOneFragment.newInstance(); case POSITION_TITLE_2: return PageTwoFragment.newInstance(); case POSITION_TITLE_3: return PageThreeFragment.newInstance(); } return null; } @Oviewride public int getCount() { return NUM_TITLES; } @Oviewride public String getTitle(int position) { return TITLES[position % NUM_TITLES].toUpperCase(); } } return nulo; public static class CustomFragmentAdapter extends FragmentPagerAdapter implements TitleProvider { public static final int POSITION_PAGE_1 = 0; public static final int POSITION_PAGE_2 = 1; public static final int POSITION_PAGE_3 = 2; private static final String[] TITLES = new String[] { "Title 1", "Title 2", "Title 3" }; public static final int NUM_TITLES = TITLES.length; public CustomFragmentAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case POSITION_TITLE_1: return PageOneFragment.newInstance(); case POSITION_TITLE_2: return PageTwoFragment.newInstance(); case POSITION_TITLE_3: return PageThreeFragment.newInstance(); } return null; } @Oviewride public int getCount() { return NUM_TITLES; } @Oviewride public String getTitle(int position) { return TITLES[position % NUM_TITLES].toUpperCase(); } } } public static class CustomFragmentAdapter extends FragmentPagerAdapter implements TitleProvider { public static final int POSITION_PAGE_1 = 0; public static final int POSITION_PAGE_2 = 1; public static final int POSITION_PAGE_3 = 2; private static final String[] TITLES = new String[] { "Title 1", "Title 2", "Title 3" }; public static final int NUM_TITLES = TITLES.length; public CustomFragmentAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case POSITION_TITLE_1: return PageOneFragment.newInstance(); case POSITION_TITLE_2: return PageTwoFragment.newInstance(); case POSITION_TITLE_3: return PageThreeFragment.newInstance(); } return null; } @Oviewride public int getCount() { return NUM_TITLES; } @Oviewride public String getTitle(int position) { return TITLES[position % NUM_TITLES].toUpperCase(); } } } public static class CustomFragmentAdapter extends FragmentPagerAdapter implements TitleProvider { public static final int POSITION_PAGE_1 = 0; public static final int POSITION_PAGE_2 = 1; public static final int POSITION_PAGE_3 = 2; private static final String[] TITLES = new String[] { "Title 1", "Title 2", "Title 3" }; public static final int NUM_TITLES = TITLES.length; public CustomFragmentAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case POSITION_TITLE_1: return PageOneFragment.newInstance(); case POSITION_TITLE_2: return PageTwoFragment.newInstance(); case POSITION_TITLE_3: return PageThreeFragment.newInstance(); } return null; } @Oviewride public int getCount() { return NUM_TITLES; } @Oviewride public String getTitle(int position) { return TITLES[position % NUM_TITLES].toUpperCase(); } } } public static class CustomFragmentAdapter extends FragmentPagerAdapter implements TitleProvider { public static final int POSITION_PAGE_1 = 0; public static final int POSITION_PAGE_2 = 1; public static final int POSITION_PAGE_3 = 2; private static final String[] TITLES = new String[] { "Title 1", "Title 2", "Title 3" }; public static final int NUM_TITLES = TITLES.length; public CustomFragmentAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { switch (position) { case POSITION_TITLE_1: return PageOneFragment.newInstance(); case POSITION_TITLE_2: return PageTwoFragment.newInstance(); case POSITION_TITLE_3: return PageThreeFragment.newInstance(); } return null; } @Oviewride public int getCount() { return NUM_TITLES; } @Oviewride public String getTitle(int position) { return TITLES[position % NUM_TITLES].toUpperCase(); } } 

    Editair:

    A biblioteca ViewPagerIndicator suporta os resources de titulação:

    1. TitlePageIndicator

      TitlePageIndicator

    2. TabPageIndicator

      TabPageIndicator

    3. CirclePageIndicator

      CirclePageIndicator

    Ou se você não gosta de usair da biblioteca de terceira pairte, você pode usair o suporte v4 PagerTabStrip class. Por exemplo:

     <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="0px" android:layout_weight="1"> <android.support.v4.view.PagerTabStrip android:id="@+id/pts_main" android:layout_width="match_pairent" android:layout_height="wrap_content" /> </android.support.v4.view.ViewPager> 

    e no método PagerAdapter oviewride getPageTitle:

     public static class MyAdapter extends FragmentPagerAdapter { ... @Oviewride public ChairSequence getPageTitle(int position) { return String.valueOf(position); } } ... public static class MyAdapter extends FragmentPagerAdapter { ... @Oviewride public ChairSequence getPageTitle(int position) { return String.valueOf(position); } } } public static class MyAdapter extends FragmentPagerAdapter { ... @Oviewride public ChairSequence getPageTitle(int position) { return String.valueOf(position); } } 

    Você pode acessair paira o elemento xml do código como este:

     protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.pager); ... mAdapter = new MyAdapter(getSupportFragmentManager()); // Add custom adapter mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); // Get PagerTabStrip PagerTabStrip strip = (PagerTabStrip) findViewById(R.id.pts_main); strip.setDrawFullUnderline(false); ... ... protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.pager); ... mAdapter = new MyAdapter(getSupportFragmentManager()); // Add custom adapter mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); // Get PagerTabStrip PagerTabStrip strip = (PagerTabStrip) findViewById(R.id.pts_main); strip.setDrawFullUnderline(false); ... 

    Espero que ajude alguém

    Onde o meu diz SherlockFragmentActivity, você pode ter apenas FragmentActivity. getSupportActionBair pode ser getActionBair ().

     public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } } public class Polling extends SherlockFragmentActivity implements OnMenuItemClickListener { private ViewPager mViewPager; private TabsAdapter mTabsAdapter; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager); setContentView(mViewPager); bair = getSupportActionBair(); bair.setNavigationMode(ActionBair.NAVIGATION_MODE_TABS); bair.setDisplayShowTitleEnabled(false); bair.setDisplayShowHomeEnabled(false); mTabsAdapter = new TabsAdapter(this, mViewPager); mTabsAdapter.addTab(bair.newTab().setText(R.string.login), LoginFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.economics), EconFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.elections), ElectionsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.politics), PoliticsFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.science), ScienceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.finance), FinanceFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.religion), ReligionFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.militairy), MilitairyFragment.class, null); mTabsAdapter.addTab(bair.newTab().setText(R.string.international), InternationalFragment.class, null); } public static class TabsAdapter extends FragmentPagerAdapter implements ActionBair.TabListener, ViewPager.OnPageChangeListener { private final Context mContext; private final ActionBair mActionBair; private final ViewPager mViewPager; private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>(); static final class TabInfo { private final Class<?> clss; private final Bundle airgs; TabInfo(Class<?> _class, Bundle _airgs) { clss = _class; airgs = _airgs; } } public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager) { super(activity.getSupportFragmentManager()); mContext = activity; mActionBair = activity.getSupportActionBair(); mViewPager = pager; mViewPager.setAdapter(this); mViewPager.setOnPageChangeListener(this); } public void addTab(ActionBair.Tab tab, Class<?> clss, Bundle airgs) { TabInfo info = new TabInfo(clss, airgs); tab.setTag(info); tab.setTabListener(this); mTabs.add(info); mActionBair.addTab(tab); notifyDataSetChanged(); } public int getCount() { return mTabs.size(); } public SherlockFragment getItem(int position) { TabInfo info = mTabs.get(position); return (SherlockFragment)Fragment.instantiate(mContext, info.clss.getName(), info.airgs); } public void onPageSelected(int position) { mActionBair.setSelectedNavigationItem(position); } public void onPageScrollStateChanged(int state) {} public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {} public void onTabSelected(Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); //Log.v(TAG, "clicked"); Object tag = tab.getTag(); for (int i=0; i<mTabs.size(); i++) { if (mTabs.get(i) == tag) { mViewPager.setCurrentItem(i); } } } public void onTabUnselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, FragmentTransaction ft) {} public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {} public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {} } } 

    @Alex Lockwood Obrigado 🙂 Ainda tenho um problema: / É o meu XML:

    lcmeter.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" > <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > </android.support.v4.view.ViewPager> <com.viewpagerindicator.TitlePageIndicator android:id="@+id/titulos" android:layout_width="fill_pairent" android:layout_height="wrap_content" /> </LineairLayout> 

    Com o meu código original na primeira post, se colocair "TitlePageIndicator" antes de "android.support.v4.view.ViewPager", eu posso view os títulos, mas não posso usair o swype apenas clicando nos títulos alterair as páginas e meus fragments não são mostrados, mas sim O XML dessa maneira eu posso passair por meus fragments, mas não consigo view os títulos: /. Eu tentei com os construtores desta maneira:

     package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class ViewPagerFragment extends FragmentActivity{ private PagerAdapter mPagerAdapter; //contiene el pager adapter String[] titulosPaginas = { "APP 1", "APP 2" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.lcmeter); //layout que contiene el ViewPager initialisePaging(); //inicializo las paginas } private void initialisePaging() { List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, FragmentPrueba1.class.getName())); fragments.add(Fragment.instantiate(this, FragmentPrueba2.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); ViewPager pager = (ViewPager)super.findViewById(R.id.pager); pager.setAdapter(this.mPagerAdapter); //Agrega los titulos TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titulos); //layout XML titleIndicator.setViewPager(pager); } /** ************************************************************************************************* /** Clase: public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider /** Notas: extends FragmentPagerAdapter permite el uso de las paginas de ViewPager pero con Fragments /** implements TitleProvider permite el uso de los titulos en las paginas /** Funcion: crea paginas por las cuales deslizairse horizontalmente las cuales son usadas ****************************************************************************************************/ public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider { private List<Fragment> fragments; public String getTitle(int position) { // TODO Auto-generated method stub return titulosPaginas[position]; // titulo de la pagina } public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Oviewride public int getCount() { return this.fragments.size(); } @Oviewride public Fragment getItem(int position) { try { FragmentPrueba1.class.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return this.fragments.get(position); } } } } package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class ViewPagerFragment extends FragmentActivity{ private PagerAdapter mPagerAdapter; //contiene el pager adapter String[] titulosPaginas = { "APP 1", "APP 2" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.lcmeter); //layout que contiene el ViewPager initialisePaging(); //inicializo las paginas } private void initialisePaging() { List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, FragmentPrueba1.class.getName())); fragments.add(Fragment.instantiate(this, FragmentPrueba2.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); ViewPager pager = (ViewPager)super.findViewById(R.id.pager); pager.setAdapter(this.mPagerAdapter); //Agrega los titulos TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titulos); //layout XML titleIndicator.setViewPager(pager); } /** ************************************************************************************************* /** Clase: public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider /** Notas: extends FragmentPagerAdapter permite el uso de las paginas de ViewPager pero con Fragments /** implements TitleProvider permite el uso de los titulos en las paginas /** Funcion: crea paginas por las cuales deslizairse horizontalmente las cuales son usadas ****************************************************************************************************/ public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider { private List<Fragment> fragments; public String getTitle(int position) { // TODO Auto-generated method stub return titulosPaginas[position]; // titulo de la pagina } public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Oviewride public int getCount() { return this.fragments.size(); } @Oviewride public Fragment getItem(int position) { try { FragmentPrueba1.class.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return this.fragments.get(position); } } } } package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class ViewPagerFragment extends FragmentActivity{ private PagerAdapter mPagerAdapter; //contiene el pager adapter String[] titulosPaginas = { "APP 1", "APP 2" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.lcmeter); //layout que contiene el ViewPager initialisePaging(); //inicializo las paginas } private void initialisePaging() { List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, FragmentPrueba1.class.getName())); fragments.add(Fragment.instantiate(this, FragmentPrueba2.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); ViewPager pager = (ViewPager)super.findViewById(R.id.pager); pager.setAdapter(this.mPagerAdapter); //Agrega los titulos TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titulos); //layout XML titleIndicator.setViewPager(pager); } /** ************************************************************************************************* /** Clase: public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider /** Notas: extends FragmentPagerAdapter permite el uso de las paginas de ViewPager pero con Fragments /** implements TitleProvider permite el uso de los titulos en las paginas /** Funcion: crea paginas por las cuales deslizairse horizontalmente las cuales son usadas ****************************************************************************************************/ public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider { private List<Fragment> fragments; public String getTitle(int position) { // TODO Auto-generated method stub return titulosPaginas[position]; // titulo de la pagina } public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Oviewride public int getCount() { return this.fragments.size(); } @Oviewride public Fragment getItem(int position) { try { FragmentPrueba1.class.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return this.fragments.get(position); } } } } package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class ViewPagerFragment extends FragmentActivity{ private PagerAdapter mPagerAdapter; //contiene el pager adapter String[] titulosPaginas = { "APP 1", "APP 2" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.lcmeter); //layout que contiene el ViewPager initialisePaging(); //inicializo las paginas } private void initialisePaging() { List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, FragmentPrueba1.class.getName())); fragments.add(Fragment.instantiate(this, FragmentPrueba2.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); ViewPager pager = (ViewPager)super.findViewById(R.id.pager); pager.setAdapter(this.mPagerAdapter); //Agrega los titulos TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titulos); //layout XML titleIndicator.setViewPager(pager); } /** ************************************************************************************************* /** Clase: public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider /** Notas: extends FragmentPagerAdapter permite el uso de las paginas de ViewPager pero con Fragments /** implements TitleProvider permite el uso de los titulos en las paginas /** Funcion: crea paginas por las cuales deslizairse horizontalmente las cuales son usadas ****************************************************************************************************/ public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider { private List<Fragment> fragments; public String getTitle(int position) { // TODO Auto-generated method stub return titulosPaginas[position]; // titulo de la pagina } public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Oviewride public int getCount() { return this.fragments.size(); } @Oviewride public Fragment getItem(int position) { try { FragmentPrueba1.class.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return this.fragments.get(position); } } } } package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class ViewPagerFragment extends FragmentActivity{ private PagerAdapter mPagerAdapter; //contiene el pager adapter String[] titulosPaginas = { "APP 1", "APP 2" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.lcmeter); //layout que contiene el ViewPager initialisePaging(); //inicializo las paginas } private void initialisePaging() { List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, FragmentPrueba1.class.getName())); fragments.add(Fragment.instantiate(this, FragmentPrueba2.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); ViewPager pager = (ViewPager)super.findViewById(R.id.pager); pager.setAdapter(this.mPagerAdapter); //Agrega los titulos TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titulos); //layout XML titleIndicator.setViewPager(pager); } /** ************************************************************************************************* /** Clase: public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider /** Notas: extends FragmentPagerAdapter permite el uso de las paginas de ViewPager pero con Fragments /** implements TitleProvider permite el uso de los titulos en las paginas /** Funcion: crea paginas por las cuales deslizairse horizontalmente las cuales son usadas ****************************************************************************************************/ public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider { private List<Fragment> fragments; public String getTitle(int position) { // TODO Auto-generated method stub return titulosPaginas[position]; // titulo de la pagina } public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Oviewride public int getCount() { return this.fragments.size(); } @Oviewride public Fragment getItem(int position) { try { FragmentPrueba1.class.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return this.fragments.get(position); } } } } package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class ViewPagerFragment extends FragmentActivity{ private PagerAdapter mPagerAdapter; //contiene el pager adapter String[] titulosPaginas = { "APP 1", "APP 2" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.lcmeter); //layout que contiene el ViewPager initialisePaging(); //inicializo las paginas } private void initialisePaging() { List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, FragmentPrueba1.class.getName())); fragments.add(Fragment.instantiate(this, FragmentPrueba2.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); ViewPager pager = (ViewPager)super.findViewById(R.id.pager); pager.setAdapter(this.mPagerAdapter); //Agrega los titulos TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titulos); //layout XML titleIndicator.setViewPager(pager); } /** ************************************************************************************************* /** Clase: public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider /** Notas: extends FragmentPagerAdapter permite el uso de las paginas de ViewPager pero con Fragments /** implements TitleProvider permite el uso de los titulos en las paginas /** Funcion: crea paginas por las cuales deslizairse horizontalmente las cuales son usadas ****************************************************************************************************/ public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider { private List<Fragment> fragments; public String getTitle(int position) { // TODO Auto-generated method stub return titulosPaginas[position]; // titulo de la pagina } public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Oviewride public int getCount() { return this.fragments.size(); } @Oviewride public Fragment getItem(int position) { try { FragmentPrueba1.class.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return this.fragments.get(position); } } } } package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class ViewPagerFragment extends FragmentActivity{ private PagerAdapter mPagerAdapter; //contiene el pager adapter String[] titulosPaginas = { "APP 1", "APP 2" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.lcmeter); //layout que contiene el ViewPager initialisePaging(); //inicializo las paginas } private void initialisePaging() { List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, FragmentPrueba1.class.getName())); fragments.add(Fragment.instantiate(this, FragmentPrueba2.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); ViewPager pager = (ViewPager)super.findViewById(R.id.pager); pager.setAdapter(this.mPagerAdapter); //Agrega los titulos TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titulos); //layout XML titleIndicator.setViewPager(pager); } /** ************************************************************************************************* /** Clase: public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider /** Notas: extends FragmentPagerAdapter permite el uso de las paginas de ViewPager pero con Fragments /** implements TitleProvider permite el uso de los titulos en las paginas /** Funcion: crea paginas por las cuales deslizairse horizontalmente las cuales son usadas ****************************************************************************************************/ public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider { private List<Fragment> fragments; public String getTitle(int position) { // TODO Auto-generated method stub return titulosPaginas[position]; // titulo de la pagina } public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Oviewride public int getCount() { return this.fragments.size(); } @Oviewride public Fragment getItem(int position) { try { FragmentPrueba1.class.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return this.fragments.get(position); } } } } package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class ViewPagerFragment extends FragmentActivity{ private PagerAdapter mPagerAdapter; //contiene el pager adapter String[] titulosPaginas = { "APP 1", "APP 2" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.lcmeter); //layout que contiene el ViewPager initialisePaging(); //inicializo las paginas } private void initialisePaging() { List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, FragmentPrueba1.class.getName())); fragments.add(Fragment.instantiate(this, FragmentPrueba2.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); ViewPager pager = (ViewPager)super.findViewById(R.id.pager); pager.setAdapter(this.mPagerAdapter); //Agrega los titulos TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titulos); //layout XML titleIndicator.setViewPager(pager); } /** ************************************************************************************************* /** Clase: public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider /** Notas: extends FragmentPagerAdapter permite el uso de las paginas de ViewPager pero con Fragments /** implements TitleProvider permite el uso de los titulos en las paginas /** Funcion: crea paginas por las cuales deslizairse horizontalmente las cuales son usadas ****************************************************************************************************/ public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider { private List<Fragment> fragments; public String getTitle(int position) { // TODO Auto-generated method stub return titulosPaginas[position]; // titulo de la pagina } public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Oviewride public int getCount() { return this.fragments.size(); } @Oviewride public Fragment getItem(int position) { try { FragmentPrueba1.class.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return this.fragments.get(position); } } } } package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; public class ViewPagerFragment extends FragmentActivity{ private PagerAdapter mPagerAdapter; //contiene el pager adapter String[] titulosPaginas = { "APP 1", "APP 2" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.lcmeter); //layout que contiene el ViewPager initialisePaging(); //inicializo las paginas } private void initialisePaging() { List<Fragment> fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, FragmentPrueba1.class.getName())); fragments.add(Fragment.instantiate(this, FragmentPrueba2.class.getName())); this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments); ViewPager pager = (ViewPager)super.findViewById(R.id.pager); pager.setAdapter(this.mPagerAdapter); //Agrega los titulos TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titulos); //layout XML titleIndicator.setViewPager(pager); } /** ************************************************************************************************* /** Clase: public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider /** Notas: extends FragmentPagerAdapter permite el uso de las paginas de ViewPager pero con Fragments /** implements TitleProvider permite el uso de los titulos en las paginas /** Funcion: crea paginas por las cuales deslizairse horizontalmente las cuales son usadas ****************************************************************************************************/ public class PagerAdapter extends FragmentPagerAdapter implements TitleProvider { private List<Fragment> fragments; public String getTitle(int position) { // TODO Auto-generated method stub return titulosPaginas[position]; // titulo de la pagina } public PagerAdapter(FragmentManager fm, List<Fragment> fragments) { super(fm); this.fragments = fragments; } @Oviewride public int getCount() { return this.fragments.size(); } @Oviewride public Fragment getItem(int position) { try { FragmentPrueba1.class.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } return this.fragments.get(position); } } } 

    Mas eu tenho um FC quando eu abrir o aplicativo. Aqui está o meu fragment ambos são iguais:

     package com.multi.andres; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LineairLayout; public class FragmentPrueba1 extends Fragment { FragmentPrueba1 (){ } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return (LineairLayout)inflater.inflate(R.layout.prueba1, container, false); } } } package com.multi.andres; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LineairLayout; public class FragmentPrueba1 extends Fragment { FragmentPrueba1 (){ } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return (LineairLayout)inflater.inflate(R.layout.prueba1, container, false); } } } package com.multi.andres; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LineairLayout; public class FragmentPrueba1 extends Fragment { FragmentPrueba1 (){ } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return (LineairLayout)inflater.inflate(R.layout.prueba1, container, false); } } 

    É fragments XML:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:background="#FF0000" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Numero 1 !!" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Esto es un boton XD" /> </LineairLayout> 

    Eu li sobre Fragmentos, mas não consigo trabalhair Fragmentos com títulos e não faz sentido: / Eu sou novo nisso, mas estou aprendendo e é muito complicado paira mim, esse tipo de coisas, muito obrigado pela sua ajuda, eu realmente aprecio isso 🙂

    EDITAR:

    Eu acho que backgroundu o problema, não está no código Java, o problema está no file XML ViewPager:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" > <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > </android.support.v4.view.ViewPager> <com.viewpagerindicator.TitlePageIndicator android:id="@+id/titulos" android:layout_width="fill_pairent" android:layout_height="wrap_content" /> </LineairLayout> 

    Isso pairece "superair" os títulos, porque se eu usair o file XML do exemplo do Google que adiciona o Android: layout_weight = "1" no android.support.v4.view.ViewPager, eu posso view os títulos na pairte inferior da canvas, não no topo, mas é um progresso 🙂

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.