标签:
今天遇到挺纠结的问题,由于产品设计的问题,技术上涉及到activity 嵌套一级fragment,一级fragment嵌套二级fragment,在一级fragment中刷新二级fragment中的UI。
其中一级fragment中有顶部搜索栏,搜索栏下面有viewpager+fragment的布局,搜索栏输入内容后要更新子当前页面的fragment的搜索方法,并刷新UI.
adapter:
private class OrderManagerFragmentPagerAdapter extends FragmentPagerAdapter { public OrderManagerFragmentPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { switch (position) { case 0: return NewOrderFragment.newInstance(); case 1: return FollowingFragment.newInstance(); case 2: return DesperatelyFollowingFragment.newInstance(); case 3: return RobbedFragment.newInstance(); case 4: return TransferFragment.newInstance(); case 5: return ClinchDealFragment.newInstance(); case 6: return LostFragment.newInstance(); case 7: return NoEffectFragment.newInstance(); default: return null; } } @Override public CharSequence getPageTitle(int position) { return TITLES[position % TITLES.length]; } @Override public int getCount() { return TITLES.length; } }
调用adapter的getitem()并调用子当前页面的fragment的搜索方法,并刷新UI,但是出错,子fragment中UI组件为null,adapter为null;
正确调用姿势为:
int position = pager.getCurrentItem(); String searchWord = searchtv.getSearchWord(); //两层fragment嵌套,调用指定fragment的刷新操作,fuck,这方法找了好几天 Fragment fragment = getChildFragmentManager().getFragments().get(position);
获取当前显示的子fragment,然后调用子fragment的搜索方法,并刷新UI.,完美实现。
activity 嵌套一级fragment,一级fragment嵌套二级fragment,在一级fragment中刷新二级fragment中的UI
标签:
原文地址:http://www.cnblogs.com/androidsuperman/p/5212095.html