I have already created an app that has one activity which has many fragments implemented with tablistener.
I now want to add horizontal swipe gestures between the fragments but its proving very difficult.
My first question is, is there a way to just detect the swipe within the base activity (even with a fragment overlayed)?
Or what is the simplest way to retro-fit the app with a simple swipe gestures?
Skeleton code below:
<------------------Main Activity--------------->
public class MainActivity extends FragmentActivity implements TabListener {
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab tab = bar.newTab();
tab.setText("TAB1");
tab.setTabListener(this);
bar.addTab(tab);
tab = bar.newTab();
tab.setText("TAB2");
tab.setTabListener(this);
bar.addTab(tab);
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
if (tab.getPosition() == 0) {
Fragment newFragment = new Tab1Fragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, newFragment);
transaction.addToBackStack(null);
transaction.commit();
vb.vibrate(50);
}
<------------------Tab 1 Fragment--------------->
public class Tab1Fragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = inflater.inflate(R.layout.tab1_fragment, null);
}
}