How to set a ViewPager inside a Fragment

Starting in Android 4.2, there are nested fragments.http://developer.android.com/about/versions/android-4.2.html#NestedFragments The support library now also includes support for this for older Android versions. So you can do something like this: @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ViewPager mViewPager = (ViewPager) view.findViewById(R.id.viewPager); mViewPager.setAdapter(new MyAdapter(getChildFragmentManager())); } Full implementation available here: https://github.com/marcoRS/nested-fragments/tree/master/src/com/burnside/digital/nestedfragments

Detect ViewPager tab change inside Fragment

I did some digging and it turns out that ViewPager will call both: setUserVisibleHint and setMenuVisibility. I would override setUserVisibleHint since the documentation for setUserVisibleHint states: Set a hint to the system about whether this fragment’s UI is currently visible to the user. This hint defaults to true and is persistent across fragment instance state … Read more

How to get elements of fragments created by ViewPager in MainActivity?

Unfortunately the only “safe” way to do it is to check the source code of FragmentPagerAdapter, and see what tag is the fragment is added with – because findFragmentByTag is the only safe way to get a Fragment from a FragmentManager. Of course, we need to hope that this implementation detail doesn’t change between support … Read more

ViewPager in a NestedScrollView

I meet this problem ,i solve it by setFillViewport (true) <android.support.v4.widget.NestedScrollView xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:id=”@+id/nest_scrollview” android:layout_height=”match_parent” app:layout_behavior=”@string/appbar_scrolling_view_behavior” tools:context=”mio.kon.yyb.nestedscrollviewbug.ScrollingActivity” tools:showIn=”@layout/activity_scrolling”> <android.support.v4.view.ViewPager android:id=”@+id/viewpager” android:layout_width=”match_parent” android:layout_height=”match_parent”/> in activity NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.nest_scrollview); scrollView.setFillViewport (true);

Android.app Fragments vs. android.support.v4.app using ViewPager?

You can use ViewPager with native fragments from the android.app package with the adapters from the android.support.v13.app package. You have to use the v13 support jar for that. There are two versions of the adapters that work with ViewPager, the ones in the v4 package are meant to be used with support fragments, the ones … Read more

ViewPager inside a ScrollView does not scroll correclty

I had the same problem. My solution was to call requestDisallowInterceptTouchEvent when the ViewPager scroll started. Here is my code: pager.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.getParent().requestDisallowInterceptTouchEvent(true); return false; } }); pager.setOnPageChangeListener(new SimpleOnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { pager.getParent().requestDisallowInterceptTouchEvent(true); } });

Dynamic height viewpager

Made a few tweaks in your code and it is working fine now. 1] onMeasure function wasn’t proper. Use below logic @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mCurrentView == null) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); return; } int height = 0; mCurrentView.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); int h = mCurrentView.getMeasuredHeight(); if (h > height) height = … Read more

Replace one Fragment with another in ViewPager

After so many hours spent, I’ve found correct solution modifying code in that answer. It replaces Fragment in first page of ViewPager with another one, and if you return back from second Fragment, first Fragment is correctly displayed. Doesn’t matter Fragment displayed in first page, if you swipe from one page to another, it doesn’t … Read more

tech