1

enter image description here for (int i = 0; i < mFragmentTitleList.size(); i++) { mFragmentList.add(new MenuListFragment()); }

Problem is when i select or swipe tab it will display products of previous tab. suppose i have 5 tabs when i click or select 4th tab it will call 3rd tab or 2nd tab's products.

  class ViewPagerAdapter extends FragmentPagerAdapter {
        private List<android.support.v4.app.Fragment> mFragmentList = new ArrayList<>();
        private List<String> mFragmentTitleList = new ArrayList<>();

        public ViewPagerAdapter(FragmentManager fm, List<android.support.v4.app.Fragment> fragments, List<String> titleLists) {
            super(fm);
            this.mFragmentList = fragments;
            this.mFragmentTitleList = titleLists;
        }

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

        @Override
        public int getCount() {
            return mFragmentList == null ? 0 : mFragmentList.size();
        }

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

   public void onTabSelected(TabLayout.Tab tab) {
                menutitle = tab.getText().toString();}

in my api call i pass this title

if(child_menu_arrayJSONObject.getString("name").equals(CommonDetailFragment.menutitle))
Urvashi kharecha
  • 625
  • 1
  • 9
  • 26

1 Answers1

0

You need to pass a title from FragmentPagerAdapter to MenuListFragment() based on the title then you can load the relevant data into the listview. you can refer this link on how to pass variable from FragmentPagerAdapter to Fragment.

Edit: i have added a sample application please check this link

Basha K
  • 1,509
  • 1
  • 11
  • 16