ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); MainActivity.SectionsPagerAdapter adapter=(MainActivity.SectionsPagerAdapter)mViewPager.getAdapter(); LoginSectionFragment fragment=(LoginSectionFragment)getSupportFragmentManager().findFragmentByTag( "android:switcher:" + mViewPager.getId() + ":" + adapter.getItemId(1)) ; fragment.initData();
对于loginSectionFragment,不能用id值取得实例,必须用findFragmentByTag,还要注意使用getSupportFragmentManager才能得到类型合适的fragment