Unmerciful
Unmerciful

Reputation: 1335

TabLayout don't show tabs

my TabLayout don't work when I setVisible(GONE), attach any fragment to Activity. Next I setVisibility(VISIBLE) and attach other fragment where is ViewPager. And tabLayout.setupWithViewPager(this.viewPager);

Second time it works.

TabLayout is in MainActivity.

Any idea?

Upvotes: 0

Views: 880

Answers (1)

Fellow Noob
Fellow Noob

Reputation: 21

I faced this similar problem and after searching, fell upon to this link https://code.google.com/p/android/issues/detail?id=180462. One of the solution is to call "setupWithViewPager" method in runnable posted to tabLayout. Code excerpt is as below:

final TabLayout tabLayout = (TabLayout) view.findViewById(R.id.plan_type_tabs);
ViewPager pager = (ViewPager) view.findViewById(R.id.viewpager);
tabLayout.post(new Runnable() {
    @Override
    public void run() {
        tabLayout.setupWithViewPager(pager);
    }
});

This is working for me. Hopefully, this would work for you.

Upvotes: 2

Related Questions