Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested tabs doesn't load contents and freezes #25

Closed
kshkrao3 opened this issue Nov 29, 2016 · 0 comments
Closed

Nested tabs doesn't load contents and freezes #25

kshkrao3 opened this issue Nov 29, 2016 · 0 comments

Comments

@kshkrao3
Copy link

The application contains 3 tabs - Home, About and FAQ. Within About tab, I've 2 more tabs namely - User details and Privacy Policy. Each of these will load a fragment into viewpager. Below is relevant code I am having now.

HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    Intent intentData = getIntent();
    initUI();
}

private void initUI() {
    final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb);
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFrag(new HomeFragment(), "Home");
    adapter.addFrag(new AboutFragment(), "About");
    adapter.addFrag(new FAQFragment(), "FAQ");
    viewPager.setAdapter(adapter);
    final NavigationTabStrip navigationTabStrip = (NavigationTabStrip) findViewById(R.id.nts_bottom);
    navigationTabStrip.setViewPager(viewPager, 0);
}

AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View view=inflater.inflate(R.layout.fragment_about, container, false);
    new Thread(new Runnable() {
        @Override
        public void run() {
            initUI(view);
        }
    }).start();

    return view;
}
private void initUI(View view) {
    final ViewPager viewPager = (ViewPager) view.findViewById(R.id.about_horizontal_tab);
    ViewPagerAdapter adapter = new ViewPagerAdapter(getActivity().getSupportFragmentManager());
    adapter.addFrag(new UserDetailsFragment(), "User Details");
    adapter.addFrag(new PrivacyPolicyFragment(), "Privacy Policy");
    viewPager.setAdapter(adapter);
    final NavigationTabStrip navigationTabStrip = (NavigationTabStrip) view.findViewById(R.id.nts_top);
    navigationTabStrip.setViewPager(viewPager, 0);
}

ViewPagerAdapter.java

public class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFrag(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }
}

But contents within About tab's, User Details and Privacy Policy never loads even though, when debugged, it hits the respective fragment's onCreateView method. Similarly, when I navigate to Privacy Policy tab it gets stuck there and doesn't navigate back to User Details tab on click.

How could I possibly solve this issue? Is it supported to have nested tabs in android?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant