Android: "Tipo de navegación: Fijaciones fijas + Golpe"

Estoy tratando de usar Tabs + Swipe en una aplicación y quiero usar el tipo de navegación "Fixed Tabs + Swipe" que el ADT me proporciona al crear una actividad.

Sooo ahora el ADT escupe código agradable, que ligeramente modificado …

Entiendo completamente el código y lo que está pasando … Pero ¿cómo puedo enseñar a la aplicación para utilizar mis tres fragmentos en lugar de la estúpida Dummy Frag? Significado de la palabra

No puedo encontrar ningún tutorial que trate con los ADT "Tipos de navegación" …

¡Gracias por tu ayuda!

public class MainActivity extends FragmentActivity implements ActionBar.TabListener { SectionsPagerAdapter mSectionsPagerAdapter; ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); // When swiping between different sections, select the corresponding // tab. We can also use ActionBar.Tab#select() to do this if we have // a reference to the Tab. mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { actionBar.setSelectedNavigationItem(position); } }); //Adding Tabs actionBar.addTab(actionBar.newTab().setText("Tab 1").setTabListener(this)); actionBar.addTab(actionBar.newTab().setText("Tab 2").setTabListener(this)); actionBar.addTab(actionBar.newTab().setText("Tab 3").setTabListener(this)); } @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { // When the given tab is selected, switch to the corresponding page in // the ViewPager. mViewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(ActionBar.Tab tab,FragmentTransaction fragmentTransaction) { } @Override public void onTabReselected(ActionBar.Tab tab,FragmentTransaction fragmentTransaction) { } public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { // getItem is called to instantiate the fragment for the given page. // Return a DummySectionFragment (defined as a static inner class // below) with the page number as its lone argument. Fragment fragment = new DummySectionFragment(); Bundle args = new Bundle(); args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1); fragment.setArguments(args); return fragment; } @Override public int getCount() { // Show 3 total pages. return 3; } } public static class DummySectionFragment extends Fragment { /** * The fragment argument representing the section number for this * fragment. */ public static final String ARG_SECTION_NUMBER = "section_number"; public DummySectionFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main_dummy,container, false); TextView dummyTextView = (TextView) rootView.findViewById(R.id.section_label); dummyTextView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER))); return rootView; } } } 

Pero, ¿cómo puedo enseñar a la aplicación a utilizar mis tres fragmentos en lugar de la estúpida Dummy Frag?

Observará que DummySectionFragment se hace referencia en getItem() del SectionsPagerAdapter :

 @Override public Fragment getItem(int position) { // getItem is called to instantiate the fragment for the given page. // Return a DummySectionFragment (defined as a static inner class // below) with the page number as its lone argument. Fragment fragment = new DummySectionFragment(); Bundle args = new Bundle(); args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1); fragment.setArguments(args); return fragment; } 

Si desea utilizar fragmentos diferentes, modifique getItem() para devolver el fragmento que desee, dada la position suministrada (número de página basado en 0).

una caja de conmutación para establecer los fragmentos es fácil y lo hace realmente claro. Deja que cada fragmento infle la vista de raíz en tu xml

 @Override public Fragment getItem(int index) { Fragment fragment = null; switch(index){ case 0: fragment = new Fragment1(); break; case 1: fragment = new Fragment2(); break; case 2: fragment = new Fragment3(); break; default: break; } //set args if necessary (which it isn't?) Bundle args = new Bundle(); args.putInt(ObjectFragment.ARG_OBJECT, index + 1); fragment.setArguments(args); //return fragment return fragment; } 
  • Android WebView en diferentes pestañas
  • TabHost and tabWidget icon problema
  • Android: ¿Por qué no debo usar actividades dentro de pestañas?
  • ¿Cómo cambiar el texto de la pestaña de android en la mosca?
  • Cambiar el estilo de fuente en las pestañas de la barra de acción con Sherlock
  • Android: el uso de la memoria aumenta cada vez que se hace clic en la pestaña (cuando se utiliza el grupo de actividades)
  • Pestañas android - iniciar una nueva actividad
  • Android: GestureDetector no funciona (gestureDetector.onTouchEvent (evento) siempre es falso) con Tabs (TabActivity, Tabwidget)
  • Desplazamiento de títulos como en Google Play
  • Cómo evitar el parpadeo en la barra de acción mientras showinh y ocultarlo en el desplazamiento
  • Barra de Acción de Android Icono de Sherlock para cada pestaña de recursos
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.