Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Refer to this SO questionthis SO question for more information on how to achieve this.

Refer to this SO question for more information on how to achieve this.

Refer to this SO question for more information on how to achieve this.

Bounty Awarded with 50 reputation awarded by Emil Adz
Format code. Add links to documentation.
Source Link
user1521536
user1521536

I think this should be tackled with a Non Swipeable ViewPager. There is no way the view pager and the underlying FragmentsFragments should respond to the swiping gesture. The methods to override to disable swiping within the ViewPager are;ViewPager are:

  1. onTouchEventonTouchEvent() - return falsereturns false.
  2. onInterceptTouchEvent()- returns onInterceptTouchEventfalse- return false.

Refer to this SO answerquestion for more information on how to achieve this.

Next up you want to be using Fragments within each of your pager holders. So we're building the following layout;layout:

enter image description here

Within the parent activity a FragmentPagerAdapter is instantiated and your tabs added with a tag;tag:

###Activity changes onCreate(final Bundle saveInstanceState) { final FragmentPagerAdapter myTabAdapter = new MyFragmentPagerAdapter(, <Your activity context, this>); myTabAdapter.addTab(getActionBar().newTab(), "YOUR TAG", "Your Title"); // etc... }

Activity changes

@Override protected void onCreate(final Bundle saveInstanceState) { final FragmentPagerAdapter myTabAdapter = new MyFragmentPagerAdapter( <Your ViewPager View>, <Your activity context, this>); myTabAdapter.addTab(getActionBar().newTab(), "YOUR TAG", "Your Title"); // etc... } 

So this gives us the frame of the diagram above. A hosting activity, containing a ViewPagerViewPager and the underlying tabs. Next up is getting the Fragments Fragments (containing your tables) into each of the respective tabs. This is handled by the FragmentPagerAdapter implementation;implementation:

###Fragment Adapter (inner class to activity) private class MyFragmentPagerAdapter extends FragmentPagerAdapter implements ActionBar.TabListener, ViewPager.OnPageChangeListener {

Fragment adapter (inner class to activity):

private class MyFragmentPagerAdapter extends FragmentPagerAdapter implements ActionBar.TabListener, ViewPager.OnPageChangeListener { /**   * Constructs a pager adapter to back a {@link ViewPager}.   *    * @param pager *  The {@link ViewPager} widget.   * @param activityContext *  The context the widget is being added under.   */  public SpotMenuFragmentPagerAdapter(final ViewPager pager,  final Context activityContext) {   super(getFragmentManager());   pager.setAdapter(this);   this.context = activityContext;   }  /**   * Adds a tab to the hosting activity action bar.   *    * @param newTab *  The tab to add.   * @param tag  * The tab tag for id purposes.   * @param label *  The label of the tab displayed to the user.   */  public void addTab(final ActionBar.Tab newTab, final String tag,  final String label) {   newTab.setTag(tag);   newTab.setText(label);   newTab.setTabListener(this);   getSupportActionBar().addTab(newTab);   }  /**   * This is where you do the work of building the correct fragment based * based  * on the tab currently selected.   *    * @see FragmentPagerAdapter#getItem(int)   */  @Override  public Fragment getItem(final int position) {   final Tab tab = getActionBar().getTabAt(position);   if ("MY TAG".equals(tab.getTag().toString()) {   // instantiate the fragment (table) for "MY TAG"   } else {   // instantiate something else...   }  }  /**   * One fragment per tab. *    * @see android.support.v4.view.PagerAdapter#getCount()   */  @Override  public int getCount() {   return getSupportActionBar().getTabCount();  }  /**   * @see ViewPager.OnPageChangeListener#onPageScrollStateChanged(int)   */  @Override  public void onPageScrollStateChanged(final int arg0) {   // No-op.  }    /**   * @see ViewPager.OnPageChangeListener#onPageScrolled(int, float, int)   */  @Override  public void onPageScrolled(final int arg0, final float arg1,  final int arg2) {   // No-op.  }    /**   * @see ViewPager.OnPageChangeListener#onPageSelected(int)   */  @Override  public void onPageSelected(final int position) {   getSupportActionBar().setSelectedNavigationItem(position);  }    /**   * @see TabListener#onTabSelected(app.ActionBar.Tab, *  app.FragmentTransaction)   */  @Override  public void onTabSelected(final Tab tab, final FragmentTransaction ft) {   viewPager.setCurrentItem(tab.getPosition());  }    /**   * @see TabListener#onTabUnselected(ActionBar.Tab, *  app.FragmentTransaction)   */  @Override  public void onTabUnselected(final Tab tab, final FragmentTransaction ft) {   // No-op.  }    /**   * @see TabListener#onTabReselected(ActionBar.Tab,app.FragmentTransaction)   */  @Override  public void onTabReselected(final Tab tab, final FragmentTransaction ft) {   // No-op.   } } 

So hopefully by this point we have an activity hosting a 'non-swipeable' view pager and a mechanism for switching tabs in the form of the tab bar underneath the title (or alongside depending on the screensizescreen size). From this point I am sure you could customise to replace the tab bar with some navigational arrows.

Note.Note: A lot of that was written from memory but hopefully I've conveyed the gist of where I would go with this.

##Update

Update

I think this should be tackled with a Non Swipeable ViewPager. There is no way the view pager and the underlying Fragments should respond to the swiping gesture. The methods to override to disable swiping within the ViewPager are;

  1. onTouchEvent - return false.
  2. onInterceptTouchEvent- return false.

Refer to this SO answer for more information on how to achieve this.

Next up you want to be using Fragments within each of your pager holders. So we're building the following layout;

enter image description here

Within the parent activity a FragmentPagerAdapter is instantiated and your tabs added with a tag;

###Activity changes onCreate(final Bundle saveInstanceState) { final FragmentPagerAdapter myTabAdapter = new MyFragmentPagerAdapter(, <Your activity context, this>); myTabAdapter.addTab(getActionBar().newTab(), "YOUR TAG", "Your Title"); // etc... }

So this gives us the frame of the diagram above. A hosting activity, containing a ViewPager and the underlying tabs. Next up is getting the Fragments (containing your tables) into each of the respective tabs. This is handled by the FragmentPagerAdapter implementation;

###Fragment Adapter (inner class to activity) private class MyFragmentPagerAdapter extends FragmentPagerAdapter implements ActionBar.TabListener, ViewPager.OnPageChangeListener {

/** * Constructs a pager adapter to back a {@link ViewPager}. * * @param pager The {@link ViewPager} widget. * @param activityContext The context the widget is being added under. */ public SpotMenuFragmentPagerAdapter(final ViewPager pager, final Context activityContext) { super(getFragmentManager()); pager.setAdapter(this); this.context = activityContext; } /** * Adds a tab to the hosting activity action bar. * * @param newTab The tab to add. * @param tag The tab tag for id purposes. * @param label The label of the tab displayed to the user. */ public void addTab(final ActionBar.Tab newTab, final String tag, final String label) { newTab.setTag(tag); newTab.setText(label); newTab.setTabListener(this); getSupportActionBar().addTab(newTab); } /** * This is where you do the work of building the correct fragment * based on the tab currently selected. * * @see FragmentPagerAdapter#getItem(int) */ @Override public Fragment getItem(final int position) { final Tab tab = getActionBar().getTabAt(position); if ("MY TAG".equals(tab.getTag().toString()) { // instantiate the fragment (table) for "MY TAG" } else { // instantiate something else... } } /** * One fragment per tab. * @see android.support.v4.view.PagerAdapter#getCount() */ @Override public int getCount() { return getSupportActionBar().getTabCount(); } /** * @see ViewPager.OnPageChangeListener#onPageScrollStateChanged(int) */ @Override public void onPageScrollStateChanged(final int arg0) { // No-op. }   /** * @see ViewPager.OnPageChangeListener#onPageScrolled(int, float, int) */ @Override public void onPageScrolled(final int arg0, final float arg1, final int arg2) { // No-op. }   /** * @see ViewPager.OnPageChangeListener#onPageSelected(int) */ @Override public void onPageSelected(final int position) { getSupportActionBar().setSelectedNavigationItem(position); }   /** * @see TabListener#onTabSelected(app.ActionBar.Tab, app.FragmentTransaction) */ @Override public void onTabSelected(final Tab tab, final FragmentTransaction ft) { viewPager.setCurrentItem(tab.getPosition()); }   /** * @see TabListener#onTabUnselected(ActionBar.Tab, app.FragmentTransaction) */ @Override public void onTabUnselected(final Tab tab, final FragmentTransaction ft) { // No-op. }   /** * @see TabListener#onTabReselected(ActionBar.Tab,app.FragmentTransaction) */ @Override public void onTabReselected(final Tab tab, final FragmentTransaction ft) { // No-op. } } 

So hopefully by this point we have an activity hosting a 'non-swipeable' view pager and a mechanism for switching tabs in the form of the tab bar underneath the title (or alongside depending on the screensize). From this point I am sure you could customise to replace the tab bar with some navigational arrows.

Note. A lot of that was written from memory but hopefully I've conveyed the gist of where I would go with this.

##Update

I think this should be tackled with a Non Swipeable ViewPager. There is no way the view pager and the underlying Fragments should respond to the swiping gesture. The methods to override to disable swiping within the ViewPager are:

  1. onTouchEvent() - returns false.
  2. onInterceptTouchEvent()- returns false.

Refer to this SO question for more information on how to achieve this.

Next up you want to be using Fragments within each of your pager holders. So we're building the following layout:

Within the parent activity a FragmentPagerAdapter is instantiated and your tabs added with a tag:

Activity changes

@Override protected void onCreate(final Bundle saveInstanceState) { final FragmentPagerAdapter myTabAdapter = new MyFragmentPagerAdapter( <Your ViewPager View>, <Your activity context, this>); myTabAdapter.addTab(getActionBar().newTab(), "YOUR TAG", "Your Title"); // etc... } 

So this gives us the frame of the diagram above. A hosting activity, containing a ViewPager and the underlying tabs. Next up is getting the Fragments (containing your tables) into each of the respective tabs. This is handled by the FragmentPagerAdapter implementation:

Fragment adapter (inner class to activity):

private class MyFragmentPagerAdapter extends FragmentPagerAdapter implements ActionBar.TabListener, ViewPager.OnPageChangeListener { /**   * Constructs a pager adapter to back a {@link ViewPager}.   *    * @param pager *  The {@link ViewPager} widget.   * @param activityContext *  The context the widget is being added under.   */  public SpotMenuFragmentPagerAdapter(final ViewPager pager,  final Context activityContext) {   super(getFragmentManager());   pager.setAdapter(this);   this.context = activityContext;   }  /**   * Adds a tab to the hosting activity action bar.   *    * @param newTab *  The tab to add.   * @param tag  * The tab tag for id purposes.   * @param label *  The label of the tab displayed to the user.   */  public void addTab(final ActionBar.Tab newTab, final String tag,  final String label) {   newTab.setTag(tag);   newTab.setText(label);   newTab.setTabListener(this);   getSupportActionBar().addTab(newTab);   }  /**   * This is where you do the work of building the correct fragment based   * on the tab currently selected.   *    * @see FragmentPagerAdapter#getItem(int)   */  @Override  public Fragment getItem(final int position) {   final Tab tab = getActionBar().getTabAt(position);   if ("MY TAG".equals(tab.getTag().toString()) {   // instantiate the fragment (table) for "MY TAG"   } else {   // instantiate something else...   }  }  /**   * One fragment per tab. *    * @see android.support.v4.view.PagerAdapter#getCount()   */  @Override  public int getCount() {   return getSupportActionBar().getTabCount();  }  /**   * @see ViewPager.OnPageChangeListener#onPageScrollStateChanged(int)   */  @Override  public void onPageScrollStateChanged(final int arg0) {   // No-op.  }  /**   * @see ViewPager.OnPageChangeListener#onPageScrolled(int, float, int)   */  @Override  public void onPageScrolled(final int arg0, final float arg1,  final int arg2) {   // No-op.  }  /**   * @see ViewPager.OnPageChangeListener#onPageSelected(int)   */  @Override  public void onPageSelected(final int position) {   getSupportActionBar().setSelectedNavigationItem(position);  }  /**   * @see TabListener#onTabSelected(app.ActionBar.Tab, *  app.FragmentTransaction)   */  @Override  public void onTabSelected(final Tab tab, final FragmentTransaction ft) {   viewPager.setCurrentItem(tab.getPosition());  }  /**   * @see TabListener#onTabUnselected(ActionBar.Tab, *  app.FragmentTransaction)   */  @Override  public void onTabUnselected(final Tab tab, final FragmentTransaction ft) {   // No-op.  }  /**   * @see TabListener#onTabReselected(ActionBar.Tab,app.FragmentTransaction)   */  @Override  public void onTabReselected(final Tab tab, final FragmentTransaction ft) {   // No-op.   } } 

So hopefully by this point we have an activity hosting a 'non-swipeable' view pager and a mechanism for switching tabs in the form of the tab bar underneath the title (or alongside depending on the screen size). From this point I am sure you could customise to replace the tab bar with some navigational arrows.

Note: A lot of that was written from memory but hopefully I've conveyed the gist of where I would go with this.

Update

updated question response
Source Link
BrantApps
  • 6.5k
  • 2
  • 30
  • 63

##Update

In response to the updated question: you can set the tab to be any old view. Set the TabSpec accordingly. Apologies I haven't used this myself.

##Update

In response to the updated question: you can set the tab to be any old view. Set the TabSpec accordingly. Apologies I haven't used this myself.

deleted 1 characters in body
Source Link
BrantApps
  • 6.5k
  • 2
  • 30
  • 63
Loading
Source Link
BrantApps
  • 6.5k
  • 2
  • 30
  • 63
Loading