ogaclejapan / SmartTabLayout

A custom ViewPager title strip which gives continuous feedback to the user when scrolling
Apache License 2.0
7.09k stars 1.34k forks source link

How can add after asyncTask ? #105

Closed phuanh004 closed 8 years ago

phuanh004 commented 8 years ago
FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
        getSupportFragmentManager(), FragmentPagerItems.with(this)
        .add(R.string.titleA, PageFragment.class)
        .add(R.string.titleB, PageFragment.class)
        .create());

ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(adapter);

SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
viewPagerTab.setViewPager(viewPager);

And I want

FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
        getSupportFragmentManager(), FragmentPagerItems.with(this)
        .create());

ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
...
onPostExcute(){

for(int i=0;i<10;i++){
        adapter.add("Page "+i, PageFragment.class);
}         // How can I do this ?

...
viewPager.setAdapter(adapter);

SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
viewPagerTab.setViewPager(viewPager);
}
ogaclejapan commented 8 years ago

Hi, @phuanh004

Please refer to the demo. https://github.com/ogaclejapan/SmartTabLayout/blob/master/demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoActivity.java#L46-L55