Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 通过子片段访问父片段大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的子片段以及如何从这个片段访问我的父片段请帮我修复它
public class Profilefragmant extends Fragment {
public Profilefragment(){}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceStatE) {

    View rootView = inflater.inflate(R.layout.profile_layout,container,falsE);

    TextView VE = (TextView) rootView.findViewById(R.id.profile_view_enquiry);
    VE.setOnClickListener(new View.onClickListener(){
        public void onClick (View view){
            Fragment fragment = null;

            fragment = new Enquiryfragment();
            replaceFragment(fragment);
        }
    });



    return rootView;
}
public void replaceFragment(Fragment someFragment) {
    android.support.v4.app.Fragmenttransaction transaction = getFragmentManager().begintransaction();
    transaction.replace(R.id.containerView,someFragment);
    transaction.addToBACkStack(null);
    transaction.commit();
}
}

运行项目时这是我的错误

java.lang.IllegalArgume@R_489_10443@ception: No view found for id 0x7f0c0099 (com.knrmarine.knr:id/containerView) for fragment EnquiryActivity{3754711 #2 id=0x7f0c0099}

这是我的Enquiryfragment代码

public class Enquiryfragmant extends Fragment {
public Enquiryfragment(){}
@Override
public View onCreateView(LayoutInflater inflater,Bundle savedInstanceStatE) {

    View rootView = inflater.inflate(R.layout.enquiry_layout,falsE);
return rootView;}}

解决方法

您可以通过以下方式获取父Fragment的参
ParentFragment parentFrag = ((ParentFragment)ChildFragment.this.getParentFragment());
parentFrag@L_827_4@meMethod();

我在我的ViewPager中使用过它.如果您有其他要求,Interface或EventBus是两个常规要求.

大佬总结

以上是大佬教程为你收集整理的android – 通过子片段访问父片段全部内容,希望文章能够帮你解决android – 通过子片段访问父片段所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。