Here is an example of using a ViewPager to get your "swipe" result.
LAYOUT
Make sure your layout is similar to this and has the ViewPager.
[HIGH=JAVA]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android

rientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/body_background">
<include layout="@layout/pagerbar" />
<include layout="@layout/colorstrip" />
<android.support.v4.view.ViewPager
android:id="@+id/example_pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
[/HIGH]
ACTIVITY
Setup your PagerAdapter in your "FragmentActivity" and make sure you implement "OnPageChangeListener". Then properly setup your PagerAdapter in your onCreate.
[HIGH=JAVA]
public class Activity extends FragmentActivity implements ViewPager.OnPageChangeListener {
...
public void onCreate(Bundle savedInstanceState) {
PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager());
pager = (ViewPager) findViewById(R.id.example_pager);
pager.setAdapter(adapter);
pager.setOnPageChangeListener(this);
pager.setCurrentItem(MyFragment.PAGE_LEFT);
...
}
/* setup your PagerAdapter which extends FragmentPagerAdapter */
static class PagerAdapter extends FragmentPagerAdapter {
public static final int NUM_PAGES = 2;
private MyFragment[] mFragments = new MyFragment[NUM_PAGES];
public PagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
@Override
public int getCount() {
return NUM_PAGES;
}
@Override
public Fragment getItem(int position) {
if (mFragments[position] == null) {
/* this calls the newInstance from when you setup the ListFragment */
mFragments[position] = MyFragment.newInstance(position);
}
return mFragments[position];
}
}
...
[/HIGH]
FRAGMENT
When you setup your actual ListFragment (your listViews) you can create multiple instances with arguments like the following:
[HIGH=JAVA]
public static final int PAGE_LEFT = 0;
public static final int PAGE_RIGHT = 1;
static MyFragment newInstance(int num) {
MyFragment fragment = new MyFragment();
Bundle args = new Bundle();
args.putInt("num", num);
fragment.setArguments(args);
return fragment;
}
[/HIGH]
When you reload the listViews (how ever you decide to implement this) you can figure out which fragment instance you are on using the arguments like so:
[HIGH=JAVA]
mNum = getArguments() != null ? getArguments().getInt("num") : 1;
[/HIGH]
If you step through your code you will notice that it will step through each instance so the above code is only needed in your onCreate and a reload method may look like this:
[HIGH=JAVA]
private void reloadFromArguments() {
/* mNum is a variable which was created for each instance in the onCreate */
switch (mNum)
{
case PAGE_LEFT:
/* maybe a query here would fit your needs? */
break;
case PAGE_RIGHT:
/* maybe a query here would fit your needs? */
break;
}
}
[/HIGH]
Few Sources that may help you out with examples that you could build from rather then starting from scratch:
More explanation and examples:
Peter Kuterna's blog: ViewPager meets Swipey Tabs
...which is references to:
android-playground - Android sample applications and projects - Google Project Hosting
More info and some good linkage:
Responsive mobile design on Android: from view pager to action bar tabs