ViewPager with FragmentPagerAdapter

Spend one hour trying find how to access my list fragment as there was no explicit fragment ID

1. Get current select view page

ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
int id = viewPager.getCurrentItem();

2. Get Fragment by tag

Fragment frag = getFragmentManager().findFragmentByTag(“android:switcher:”+R.id.pager+”:”+id);

Then you can access your fragment reference.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s