Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit:</strong> As of ACLv11 this is only needed if you <code>replace(...)</code> <code>ViewPagers</code> dynamically. </p> <p>Yes you can, but there are certain ways that are a pain, but I have even embedded FragmentViewPagers.</p> <p>If you embed in XML then when the layout is inflated you will have no problems.</p> <p>If you embed fragments dynamically within another fragment then you will get issues! Although it is possible.</p> <p>Generally involves posting to a handler which then executes after the current fragment transition then starts another, this way you can embed fragments pretty easily. But this leads to other issues, so you have to be careful how you implement this.</p> <p>FoodTestFeast has embedded ViewPagers which are removed and added dynamically.</p> <p>My Base FragmentViewPager - Fragment that holds a view pager (Which has FragmentPagerAdapter)</p> <p>I haven't seen any crashes using this yet, but let me know if anyone else does.</p> <pre><code>/** * @project FoodFeast * @author chris.jenkins * @created Dec 28, 2011 */ package couk.jenxsolution.food.ui.fragments; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.viewpagerindicator.TabPageIndicator; import couk.jenxsolution.food.R; import couk.jenxsolution.food.app.FoodApplication; /** * @author chris.jenkins */ public class QuizPagerBaseFragment extends QuizBaseFragment { // Data private FragmentStatePagerAdapter mAdapter = null; // Views private int layoutRes; private View mRootView; private ViewPager mPager; private TabPageIndicator mIndicator; // Handlers private final Handler handler = new Handler(); private Runnable runPager; private boolean mCreated = false; /** * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, * android.view.ViewGroup, android.os.Bundle) */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) mRootView = inflater.inflate(layoutRes, container, false); mPager = (ViewPager) mRootView.findViewById(R.id.pager); mPager.setOffscreenPageLimit(2); mIndicator = (TabPageIndicator) mRootView.findViewById(R.id.indicator); mIndicator.setTypeface(FoodApplication.getInstance().getTFs().getTypeFaceBold()); return mRootView; } /** * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle) */ @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (runPager != null) handler.post(runPager); mCreated = true; } /** * @see android.support.v4.app.Fragment#onPause() */ @Override public void onPause() { super.onPause(); handler.removeCallbacks(runPager); } /** * Set the ViewPager adapter from this or from a subclass. * * @author chris.jenkins * @param adapter */ protected void setAdapter(FragmentStatePagerAdapter adapter) { mAdapter = adapter; // mAdapter.notifyDataSetChanged(); runPager = new Runnable() { @Override public void run() { mPager.setAdapter(mAdapter); mIndicator.setViewPager(mPager); // mAdapter.notifyDataSetChanged(); mIndicator.setVisibility(View.VISIBLE); } }; if (mCreated) { handler.post(runPager); } } /** * Has to be set before onCreateView * * @author chris.jenkins * @param layoutRes */ protected void setLayoutRes(int layoutRes) { this.layoutRes = layoutRes; } } </code></pre> <p>FYI your layout will need to look like this (or similar): <strong>NOTE THE Indicator = GONE!</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;com.viewpagerindicator.TabPageIndicator android:id="@+id/indicator" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone"/&gt; &lt;android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload