android嵌套fragment怎么实现点击外层fragment控制内层fragment显示特定界面
1个回答
展开全部
message是一个fragment,在里面又有两个子fragment,(Firends和follow),后来把两个fragment改ViewPager方式进行切换,这时一定要注意msgAdapter=new FragmentMessagePagerAdapter(getChildFragmentManager());在new PagerAdapter时,一定要传入getChildFragmentManager(),而不是getSupportFragmentManager,
一级Fragment里的OnCreateView方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mActivity = getActivity();
View view = inflater.inflate(R.layout.activity_fragment_message,container,false);
Button btnFriends= (Button) view.findViewById(R.id.btn_friends);
Button btnFollow= (Button) view.findViewById(R.id.btn_follow);
btnFriends.setOnClickListener(this);
btnFollow.setOnClickListener(this);
vp = (NoScrollViewPager) view.findViewById(R.id.vp_noscroll);
list_fragments=new ArrayList<Fragment>();
//把两个子fragment实例化然后装到集合里
mFrendsFragment=new Message_Friends_Fragment();
list_fragments.add(mFrendsFragment);
mFollowFragment=new Message_Follow_Fragment();
list_fragments.add(mFollowFragment);
msgAdapter=new FragmentMessagePagerAdapter(getChildFragmentManager());
一级Fragment里的OnCreateView方法:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mActivity = getActivity();
View view = inflater.inflate(R.layout.activity_fragment_message,container,false);
Button btnFriends= (Button) view.findViewById(R.id.btn_friends);
Button btnFollow= (Button) view.findViewById(R.id.btn_follow);
btnFriends.setOnClickListener(this);
btnFollow.setOnClickListener(this);
vp = (NoScrollViewPager) view.findViewById(R.id.vp_noscroll);
list_fragments=new ArrayList<Fragment>();
//把两个子fragment实例化然后装到集合里
mFrendsFragment=new Message_Friends_Fragment();
list_fragments.add(mFrendsFragment);
mFollowFragment=new Message_Follow_Fragment();
list_fragments.add(mFollowFragment);
msgAdapter=new FragmentMessagePagerAdapter(getChildFragmentManager());
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询