0

I have project:

Activity with 2 dynamically added fragments

Fragment#1 that is a list of objects (using listView and adapter), when user click on list item here comes Fragment#2

Fragment#2 that is a description of an object. Here i want to use FragmentPager to simple change objects

I have tried to use that solution but in my opinion I have to use it in fragment (not in Activity as example shows)... or in adapter?? i don't know...

How Can I do that?

MattiahIT
  • 87
  • 9
  • Please, Have a look at this [answer](http://stackoverflow.com/a/18413437/3330969). – Lucifer Mar 20 '14 at 08:42
  • https://github.com/commonsguy/cw-omnibus/tree/master/ViewPager/Nested – Sree Mar 20 '14 at 08:44
  • ok i have used example of @Sreekanthss and I have FragmentPager now but when I press back I have list again and then if I press again on any Item I have empty page... previous fragment replace commit works fine but now commit gives nothing... (no error, no worning, just blank page) – MattiahIT Mar 20 '14 at 10:07
  • ok I have an answer PageAdapter should extend 'FragmentStatePagerAdapter' now everything works fine :) Thanks – MattiahIT Mar 20 '14 at 10:35

1 Answers1

0

It's really easy one, Simply you've to convert that FragmentActivity of the ViewPager to Fragment using the following way

Make your class extend Fragment not FragmentActivity in which you want to use ViewPager

then create the following methods to work with Fragmets using ViewPager

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.view_reminder_main, container,
                false);

        view_pager = (ViewPager) view
                .findViewById(R.id.child_main_pager);
        return view;
    }

@Override
    public void onActivityCreated(Bundle arg0) {
        super.onActivityCreated(arg0);

            view_pager.setAdapter(new CustomFragmetPagerAdapter(
                    getChildFragmentManager()));
    }

keep the following in field level

private ViewPager view_reminder_pager;

I hope this would help you :)

Akbarsha
  • 2,422
  • 23
  • 34