Skip to content Skip to sidebar Skip to footer

How I Get The Current Visible Fragment From View Pager Adapter..?

I have implemented these lines of code but it is not working . pagerAdapter= new AbstractPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager)findViewById(R.id.pa

Solution 1:

To get the currently visible fragment instance try the following

viewPager.setOnPageChangeListener(this);

and in the following method

@Override
public void onPageSelected(int position) {

    if (position == 0)
        setFragmentFor(0);
    if (position == 1)
        setFragmentFor(1);
            .
            .
            .
            // Upto how many fragments you've in your ViewPager
}

so in the setFragmentFor() method you should write your own logic to get the new Instance of Fragment depending upon the argument value passed over the setFragmentFor().

Post a Comment for "How I Get The Current Visible Fragment From View Pager Adapter..?"