Actually, I am using whole application in a single activity by fragments in main view container.
One fragment contains a viewPager when I clicked over a header button fragment replaced by LoginFragment
and on Back we maintaining backstack
so fragment containing viewPager will be on top but there we got blank view of current item in viewPager
.
This is my Solution and i have searched a lot of the answer so if you got a better one please share it with me..
i switched the ViewPager to the Activity
Activity XML
<RelativeLayout ....
xmlns.
<FrameLayout
android:id="@+id/container"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
</...viewPager>
Activity Class
public MainActivity extends Activity .... {
private boolean mShowPager;
private FrameLayout mContainer;
private ViewPager mPager;
//Inflate them
public void showViewPager() {
mPager.setVisibility(View.Visible);
mContainer.setVisibilty(View.Gone);
}
public void showContainer() {
mContainer.setVisibility(View.Visible);
mPager.setVisibilty(View.Gone);
}
public void showViewPager(boolean show) {
mShowPager = show;
}
@override
public void onBackPressed() {
if(mShowPager) {
showViewPager();
}
super.onBackPressed();
Fragment Example
public void onAttach(Activity activity) {
((MainActivity)activity).showViewPager(true);
((MainActivity)activity).showContainer();
//True means when back pressed back show ViewPager //Back means still show Container but do Back pressed Info : you decide what you want to show ViewPager or the Container that contain the Fragments plus you can use the BackStack if needed.
Hope it helps its helped me.
I got an answer by my self on debugging. Problem was I was using fragmentPager inside fragment so there for adapter initialization we have to pass getChildFragmentManager() instead of getFragmentManager()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With