Android viewpager inside another viewpager

I am trying to have a viewpager with multiple views (say 5?) And in one of the views (say 3rd view?). I have to add another viewer, after searching for a while, I came up with some questions that I could not get an exact answer for my situation.

  • How can I implement a viewpager inside a fragment of another viewpager?
  • If it is possible to complete the above task, how will the touch function be processed for viewing? Does the internal viewer change the appearance, which will affect the external?

I really do not need some kind of code solution, but it looks more like a conceptual solution, so I do not ask anyone to do their own coding, but I was in silence from the android, and I rather heard a new concept from professionals.

early.

Edit:

Ok, I managed to do this at some point, but now I am facing another problem. here is a call to the snippet that 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 an expression of the 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 go to the next page, and then I can easily go back to the first page, but when I go to the third page and then go back to the first page, which is to my other viewpager, this causes an error:

 java.lang.IllegalStateException: Recursive entry to executePendingTransactions 

I'm not sure why this is happening, I did a few searches, and it looks like I'm using a viewpager inside a fragment ...

Any help would be appreciated.

+4
source share

Source: https://habr.com/ru/post/1484012/


All Articles