since ICS, Android has introduced a range of horizontally swiping navigation actions. i like them since they look very naturally-sophisticated. as an example to get started using all sorts of swiping navigation, this post talks about how to use the "swipe + title strip" type.

stuff that help understanding this post:

  • how to use Fragments (i.e. on honeycomb or higher Androids)

what i want to achieve, is an Activity that shows three screens of UI content that can horizontally swipe to replace each other (just like Tasks or Play Store). here, each of these screens would be a separate Fragment.

the general process:

  1. create a class in your package inside the src folder, and extend FragmentActivity
  2. create a class inside your FragmentActivity subclass, and extend FragmentPagerAdapter 
  3. create Fragment classes (i.e. .java files) in your package inside the src folder for each "screen", and create corresponding layout files
  4. the layout file for your MainActivity needs to be just a PagerTitleStrip inside a ViewPager
  5. in a method of the MainActivity, find the ViewPager in your main layout, then set its adapter to be an instance of the FragmentPagerAdapter class

explanation:

from within some of its Override-ed methods, the FragmentPagerAdapter creates and returns Fragment instances to be considered by the ViewPager to be each "screen".

code example:

these examples each omitted spec' details.

layout for the MainActivity - "main.xml":

<android.support.v4.view.ViewPager
    ...
    android:id="@+id/myPager"
    ...>
    <android.support.v4.view.PagerTitleStrip 
        .../>
</android.support.v4.view.ViewPager>

Fragment classes - "Frag1.java":

...
public class Frag1 extends Fragment {

	@Override
	public View onCreateView(LayoutInflater li,ViewGroup vg,Bundle bun){
		return li.inflate(R.layout.frag1, vg, false);
	}
}

MainActivity class - "MainActivity.java":

...
public class MainActivity extends FragmentActivity {
	SectionPagerAdapter mSectionPagerAdapter;
	ViewPager mViewPager;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		mSectionPagerAdapter=new SectionPagerAdapter(getSupportFragmentManager());
		mViewPager=(ViewPager)findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionPagerAdapter);
	}

	public class SectionPagerAdapter extends FragmentPagerAdapter {
		public SectionPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int pos) {
			Fragment mFragment;
			switch (pos) {
			case 0:
				mFragment = new Frag1();
				mFragment.setArguments(null);
				return mFragment;
			case 1:
				mFragment = new Frag2();
				mFragment.setArguments(null);
				return mFragment;
			case 2:
				mFragment = new Frag3();
				return mFragment;
			default:
				return null;
			}
		}

		@Override
		public int getCount() {
			return 3;
		}

		@Override
		public CharSequence getPageTitle(int pos) {
			return getResources().getStringArray(R.array.titles)[pos];
		}
	}
}

project directory structure:

...
/src/myPkg/Frag1.java
/src/myPkg/Frag2.java 
/src/myPkg/Frag3.java
/src/myPkg/MainActivity.java
/res/layout/frag1.xml
/res/layout/frag2.xml
/res/layout/frag3.xml
/res/layout/main.xml
...

that's about it. i'd appreciate you to leave a reply of your result if you try this.