this is my child fragment and how to access my parent fragment from this fragment please help me to fix it
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(); } }
this is my error while run the project
java.lang.IllegalArgumentException: No view found for id 0x7f0c0099 (com.knrmarine.knr:id/containerView) for fragment EnquiryActivity{3754711 #2 id=0x7f0c0099}
This my Enquiryfragment
code :
public class Enquiryfragmant extends Fragment { public Enquiryfragment(){} @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.enquiry_layout, container, false); return rootView;}}
Simply call your parent activity using getActivity() method.
You can get parent Fragment
's reference by :
ParentFragment parentFrag = ((ParentFragment)ChildFragment.this.getParentFragment()); parentFrag.someMethod();
I used this in my ViewPager. If you have other requirement, Interface
or EventBus
are two of the general ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With