Remove All Ads from XDA

[q][solved]View Pager doesnt adds fragments to backstack

1,157 posts
Thanks Meter: 606
Post Reply Email Thread
i have made a fragment which contains view uses list of fragments so that fragments can be added or removed dynamically.
each child fragment of viewpager is a listfragment and loads list using asynctask
now my problem is when i have 3-4 child fragments in view pager,after switching to other pages(tabs),the earlier ones in which list is already loaded are reset automatically when i swipe back to i want that they must be added to backstact so that they can be resumed.
public class TabFragment extends {
List fragments = new ArrayList();
public PagerAdapter mSectionsPagerAdapter;

ViewPager mViewPager;

String home;
ActionBar actionBar;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.tabfragment,
container, false);
mSectionsPagerAdapter = new ScreenSlidePagerAdapter(getChildFragmentManager());
mViewPager = (ViewPager) rootView.findViewById(;
actionBar = getActivity().getActionBar();

mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

public void onPageScrolled(int p1, float p2, int p3) {
// TODO: Implement this method

public void onPageSelected(int p1) { // TODO: Implement this// method
Main ma = ((Main) fragments.get(p1));
if (ma.current != null) {

public void onPageScrollStateChanged(int p1) {
// TODO: Implement this method

return rootView;

private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {

public CharSequence getPageTitle(int position) {
Main ma = ((Main) fragments.get(position));
            return new File(ma.current).getName();

public int getCount() {
// TODO: Implement this method
return fragments.size();

public ScreenSlidePagerAdapter( fm) {

public getItem(int position) { f;
f = fragments.get(position);
return f;

public void removePage(int position) {
if(position==0){Toast.makeText(getActivity(),"Main Screen Cant be removed",Toast.LENGTH_LONG).show();}else{


public void add(String text) { main = new Main();
Bundle b = new Bundle();
int p = fragments.size();
b.putString("path", text);

b.putInt("pos", p);



Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes