Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Following code snippets are mainlyfrom <a href="http://developer.android.com/training/implementing-navigation/lateral.html" rel="nofollow" title="Implementing Lateral Navigation">Android Developer</a> site. There is also a very good example app/project.</em></p> <p>Use <code>ViewPage</code> as a container for your layout, e.g. res/layout/activity_main.xml:</p> <pre><code>&lt;android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; </code></pre> <p>Implement ABS' <code>ActionBar.TabListener</code> in your class, add and extend <code>FragmentPagerAdapter</code> or <code>FragmentStatePagerAdapter</code> from support library e.g.:</p> <pre><code>public class TheDesertFoxActivity extends SherlockFragmentActivity implements ActionBar.TabListener { private AppSectionsPagerAdapter mAppSectionsPagerAdapter; private ViewPager mViewPager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); // Set up action bar final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Set up the ViewPager, attaching the adapter mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mAppSectionsPagerAdapter); mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between different app sections, select the corresponding tab actionBar.setSelectedNavigationItem(position); } }); // For each of the sections in the app, add a tab to the action bar for (int i = 0; i &lt; mAppSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by the adapter. // Also specify this Activity object, which implements the TabListener interface, as the // listener for when this tab is selected. actionBar.addTab(actionBar.newTab() .setText(mAppSectionsPagerAdapter.getPageTitle(i)) .setTabListener(this)); } } public static class AppSectionsPagerAdapter extends FragmentPagerAdapter { public AppSectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { switch (i) { Fragment fragment = new MyTabsFragment(); Bundle args = new Bundle(); args.putInt(MyTabsFragment.TAB_ID, i); fragment.setArguments(args); return fragment; } } @Override public int getCount() { return &lt;YOUR_TAB_COUNT&gt;; } } public static class MyTabsFragment extends Fragment { public static final String TAB_ID = "tab_id"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { int layoutId = -1; switch (getArguments(getInt(TAB_ID))) { case 0: layoutId = R.layout.fragment_first_tab; break; case 1: layoutId = R.layout.fragment_second_tab; break; ... ... ... default: layoutId = R.layout.fragment_default_tab; } View rootView = inflater.inflate(layoutId, container, false); return rootView; } } } </code></pre> <p>That's it. Dividers will be put by <code>ViewPager</code> for you. You do not have to add them yourself.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload