Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewPager inside fragment issue

I'm having problem with view pager which is inside of some fragment. To work with view pager I'm using FragmentPagerAdapter. And sure I'm getting java.lang.IllegalStateException: Recursive entry to executePendingTransactions exception when trying to run my app.

Most people say it's impossible to have FragmentPagerAdapter inside other fragment, so I'm sorry if this question is invalid. I was just hoping that maybe someone has some fresh ideas about this problem and its possible solution.

P.S. I've got an advice to set adapter inside of AsyncTask (I can clarify this case if someone needs it), but this solution has some bugs related with restoring such fragment state, so it's working for me.

like image 559
Orest Avatar asked Mar 29 '12 12:03

Orest


People also ask

Can you put a ViewPager in a fragment?

Steps for implementing viewpager: Adding the ViewPager widget to the XML layout (usually the main_layout). Creating an Adapter by extending the FragmentPagerAdapter or FragmentStatePagerAdapter class.

Can I use ViewPager with views not with fragments?

yes...you can use View instead of Fragment in viewpager. Here you can Find Whole example that will help you to achieve Viewpager without Fragment. Go through this documentation. Save this answer.

Is ViewPager deprecated in Android?

This method may be called by the ViewPager to obtain a title string to describe the specified page. This method is deprecated.


1 Answers

Starting with Android 4.2, you can use nested fragments. The Android support library now also includes support for this, so you can use it with older Android versions.

The basic pattern looks like this:

Fragment videoFragment = new VideoPlayerFragment();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.video_fragment, videoFragment).commit();
like image 69
Otto Allmendinger Avatar answered Sep 23 '22 23:09

Otto Allmendinger