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.