0

I have to solve this problem in rapid way because in two hours I have to send my project to my professor.

I have a fragmentviewpager with 5 fragment inside a fragment. Inside every fragment I have a table and it update with some data from json file and in base of the page position.

I take the page position with this function inside fragment container and I put it in the static int currentPage:

mPager.setOnPageChangeListener(new OnPageChangeListener() {

    @Override
    public void onPageSelected(int arg0) 
    {
        currentPage=arg0;
    }

    @Override
    public void onPageScrolled(int arg0, float arg1, int arg2) 
    {


    }

    @Override
    public void onPageScrollStateChanged(int arg0) 
    {


    }
});

Inside to onResume of each fragment inside fragmentviewpager I take the current position with the currentPage variable.

But for do a correct work, I need that I can execute onResume every time when I change page with a swipe. In what way can I do ?

This is my fragmentviewpager:

private class ScreenSlidePagerAdapter extends FragmentPagerAdapter 
    {

        // fragments to instantiate in the viewpager
        private List<Fragment> fragments;

        public ScreenSlidePagerAdapter(FragmentManager fm, List<Fragment> fragments) 
        {
            super(fm);
            this.fragments = fragments;
        }

        public void addPage(Fragment page)
        {
            fragments.add(page);
            this.notifyDataSetChanged();
        }

        @Override
        public Fragment getItem(int position) 
        {

            return this.fragments.get(position);
        }

        @Override
        public int getItemPosition(Object object) {
               return POSITION_NONE;
            }

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

How can I solve my problem ? Thank you in Advance :)

Amy
  • 4,034
  • 1
  • 20
  • 34
aeroxr1
  • 1,014
  • 1
  • 14
  • 36

1 Answers1

0

onResume does not get called all time in viewpager, you can create a public method in fragment and you can call that depending on position This link will be use full to you Getting the current Fragment instance in the viewpager

Community
  • 1
  • 1
  • do you mean to put that function inside every fragment and call in the onpageselected callback ? – aeroxr1 Aug 20 '15 at 04:05
  • I have added the fragment in this way : fragments.add(Fragment.instantiate(getActivity(),CmdPageSlider.class.getName())); fragments.add(Fragment.instantiate(getActivity(),CmdPageSlider.class.getName())); fragments.add(Fragment.instantiate(getActivity(),CmdPageSlider.class.getName())); fragments.add(Fragment.instantiate(getActivity(),CmdPageSlider.class.getName())); fragments.add(Fragment.instantiate(getActivity(),CmdPageSlider.class.getName())); In what way can I call the right interface ? – aeroxr1 Aug 20 '15 at 04:12
  • I need to reference to the current fragment to call the interface, but in what way ? – aeroxr1 Aug 20 '15 at 04:16
  • Why are you using fragments List – Narendra Kothamire Aug 20 '15 at 04:18
  • what do you suggest to use ? – aeroxr1 Aug 27 '15 at 03:26