Closed adrielcafe closed 8 years ago
Hi @adrielcafe!
Can you also show the way you're setting up your ViewPager
inside your main Activity
? As I can see it now, it's fragment-related issue. I might try to recreate your issue later today.
Yes, below is my MainActivity
. As you can see, I create 3 different instances of FeedFragment
.
public class MainActivity extends AppCompatActivity {
@Bind(R.id.coordinator_layout)
CoordinatorLayout coordinatorLayout;
@Bind(R.id.viewpager)
ViewPager viewPager;
@Bind(R.id.tabs)
TabLayout tabLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
init();
}
private void init(){
TabPagerAdapter tabPagerAdapter = new TabPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(tabPagerAdapter);
viewPager.setOffscreenPageLimit(4);
viewPager.setPageTransformer(true, new FadePageTransformer());
tabLayout.setupWithViewPager(viewPager);
}
private class TabPagerAdapter extends FragmentPagerAdapter {
public TabPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
return FeedFragment.newInstance(DbUtil.friendsFeed);
case 1:
return FeedFragment.newInstance(DbUtil.profileFeed);
case 2:
return FeedFragment.newInstance(DbUtil.favoritesFeed);
case 3:
return new FriendsFragment();;
case 4:
return new SettingsFragment();
default:
return null;
}
}
@Override
public int getCount() {
return 5;
}
}
}
@blipinsk, problem solved!
Seems that the problem was related to fragment tags and FeedAdapter
(that extends FragmentStatePagerAdapter
). When I started to using CWAC-Pager the problem was solved.
private class FeedAdapter extends ArrayPagerAdapter<FeedItemFragment> {
public PagerAdapter(FragmentManager fragmentManager, ArrayList<PageDescriptor> descriptors) {
super(fragmentManager, descriptors);
}
@Override
protected FeedItemFragment createFragment(PageDescriptor desc) {
return FeedItemFragment.newInstance(desc.getFragmentTag(), type);
}
}
Thanks for your help. Once again, this library is amazing!
Cool, glad you solved it. The stack looks nicely in your app. :+1: Cheers!
Hi @blipinsk! First of all, congrats for this great lib :)
So, I have this layout below. The first 3 tabs must show the same FlippableStackView layout, but with different content. Each tab has a different Fragment instance that handles an FlippableStackView separately.
Problem is: only first tab is showing FlippableStackView layout. It's like only one instance of FlippableStackView could exist.
More strange part is: if I put the second or third tab as first tab, FlippableStackView will init normally on that tab, but on the other tabs will not.
Layout and classes are below.
Thanks in advance!
_activitymain.xml
_fragmentstack.xml
FeedFragment.java (that handles FlippableStackView)