Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To solve your case, I used:</p> <pre><code>@Override public void onTabSelected(Tab tab, FragmentTransaction transaction) { this.mPager.setCurrentItem(tab.getPosition()); } </code></pre> <p>When a click on a tab, the view of the corresponding tab is automatically changed.</p> <p><strong>Edit:</strong> I must admit that I have some difficulties to really understand your code and what you are trying to do, so I add some more code to explain what i think you need.</p> <p>In my optinion, only one adapter is necessary for the ViewPager, and then if I'm right, you would do so:</p> <pre><code>// I took some personal code for my example private ViewPager mPager; private PageIndicator mIndicator; private TabsExampleSectionsAdapter mAdapter; // Inside the onCreate method this.mPager = (ViewPager) findViewById(R.id.pager); this.mIndicator = new TabPageIndicator(this); this.mAdapter = new TabsExampleSectionsAdapter(this.getSupportFragmentManager()); this.mPager.setAdapter(this.mAdapter); this.mIndicator.setViewPager(this.mPager); </code></pre> <p>When everything is initialized, this is how to build tabs and pager views instructions (the two are related). Also, don't mind the Section class, it's a custom data model object which contains the tag data you need but it has nothing to do with actionbarsherlock.</p> <pre><code>private void buildTabs(Section[] sections) { if (sections != null) { for (Section section : sections) { ActionBar.Tab sectionTab = getSupportActionBar().newTab(); sectionTab.setText(section.name); sectionTab.setTabListener(this); getSupportActionBar().addTab(sectionTab); // The tag ("op" or "dd" in your case for example) is contained somewhere in the section object this.mAdapter.getSections().add(section); } } } </code></pre> <p>And finally, this is the view pager adapter. It will choose what type of fragment to return following the tags you defined for each tab position:</p> <pre><code>public class TabsExampleSectionsAdapter extends FragmentPagerAdapter { private ArrayList&lt;Section&gt; mSectionsList = new ArrayList&lt;Section&gt;(); public TabsExampleSectionsAdapter(FragmentManager fragmentManager) { super(fragmentManager); } @Override public Fragment getItem(int position) { // Retrieving the cooresponding tag of position Section section = this.mSectionsList.get(position % getCount()); // Here, you check the tag to know what type of fragment you must return if (section.getTag().equals("dd")) { return FragmentDados.newInstance(position); } else if (section.getTag.equals("op")) { return FragmentOp.newInstance(position); } } @Override public int getCount() { return this.mSectionsList.size(); } @Override public CharSequence getPageTitle(int position) { return this.mSectionsList.get(position % getCount()).name.toUpperCase(); } public ArrayList&lt;Section&gt; getSections() { return this.mSectionsList; } } </code></pre> <p>In conclusion, when everything is set up, changing views doesn't have to be done manually by changing adapters and calling invalidate(). You can return different type of fragments from your adapter with a simple condition. Then, by calling:</p> <pre><code>this.mPager.setCurrentItem(position); </code></pre> <p>it changes automatically the current view by passing in the adapter's getItem(position) method. Basically, you just have to coordinate your tab positions and your tags in order to get the right type of fragment.</p> <p>Feel free to ask for more details.</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. VO
      singulars
      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