android - activity中获取到fragment 的几种方式

访问量: 98

参考:https://stackoverflow.com/questions/10903077/calling-a-fragment-method-from-a-parent-activity

1. 根据Fragment id/tag来获取:

VerifyIdentityFragment verifyIdentityFragment = (VerifyIdentityFragment)getSupportFragmentManager().findFragmentById(R.id.tab2);

2. 如果是使用了ViewPager (例如在MainActivity中), 那么就要:

            VerifyIdentityFragment verifyIdentityFragment = (VerifyIdentityFragment)viewPager.getAdapter().instantiateItem(viewPager, 1);
            verifyIdentityFragment.updateViewByIsBindedDevice();

订阅/RSS Feed

Subscribe

分类/category