4

I'm trying to have a viewpager with few views (let's say 5?) and in one of the views (let's say 3rd view?) I have to put another viewpager so after searching for a while, I've come up with some questions which I couldn't get the exact answer for my situtation.

  • How is it possible to implement a viewpager inside a fragment of another viewpager?
  • If it's possible to do the above task, how's the touch function will be handled for viewpagers ? Isn't changing views for the inner viewpager gonna affect the outer one?

I don't really need a code kinda solution but more like a concept kinda solution, so I'm not asking for anyone to do my coding, but I've been quiet away from android and I rather to hear the new concepts from the pros.

thanks in advance.

Edit:

Ok I managed to do it at some point but another problem I'm facing now. here is the call to the fragment which contains my viewpager:

Fragment fragment = new Fragment();
switch(position)
{
    case 0: fragment = new CalendarFragment();break;
    case 1: fragment = new DummySectionFragment();
            Bundle args = new Bundle();
            args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, 2);
            fragment.setArguments(args);break;
}
return fragment;

and this is the oncreate of calendarFragment class:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
    View cal = inflater.inflate(R.layout.calendar, container, false);
    viewPager = (ViewPager) cal.findViewById(R.id.calendar_pager);
    viewPager.setOnTouchListener( new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_DOWN && v instanceof ViewGroup) {
                ((ViewGroup) v).requestDisallowInterceptTouchEvent(true);
            }
        return false;
    }
    });
    viewPager.setAdapter(createCalendarAdaptor());
    viewPager.setCurrentItem(MONTHS_LIMIT / 2);
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int arg0) {
            //updateResetButtonState();
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }
    });
    return cal;
}

and I get the calendar in the first fragment and it works just fine and I can easily scroll to next page, and then I can easily move back to the first page, but when I move to 3rd page and then I go back to first page which is my other viewpager it cause an error:

java.lang.IllegalStateException: Recursive entry to executePendingTransactions

I'm not quiet sure why is it happening, I've done some searching and it appears it's because I'm using a viewpager inside a fragment...

Any help would be appreciated.

arash moeen
  • 4,533
  • 9
  • 40
  • 85
  • What happened when you tried to use a `ViewPager` in another `ViewPager`? – user Jun 02 '13 at 06:36
  • well from what I could get from the built-in ViewPager with actionbar code you have to define fragments for your viewpager, right? so I created an xml containing my custom viewpager and returning it as a view in the fragment class for my outer viewpager? I'm really confused :| – arash moeen Jun 02 '13 at 06:47
  • I'm quiet stuck here, anyone who could help me or shoot me some ideas? :\ – arash moeen Jun 04 '13 at 06:37
  • I'm pretty sure this is a very bad idea from the UI/UX point of view. – Martin Marconcini Dec 14 '13 at 19:01
  • Yes, We can defiantly add an view-pager inside the another view-pager. parent view-pager you need to add in your activity, child view-pager add in your fragment which is inflate inside your parent view-pager. – swati vishnoi Nov 20 '19 at 12:23
  • visit - https://stackoverflow.com/questions/7338823/viewpager-recursive-entry-to-executependingtransactions – swati vishnoi Nov 20 '19 at 12:26

0 Answers0