android - Create BaseFragment and extend this Fragment in ChildFragment -
i don't know whether repeated question or not, didn't found solution.
the problem is, there screen has similar views in screens, screens in fragment.
so, want create base fragment , want extend base fragment in child fragments.
i found on google, demo examples, didn't find solution.
i don't know start.
please me.
i found links not clear:
basefragment.java
public class basefragment extends fragment { public basefragment() { // required empty public constructor } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_base, container, false); } }
childfragment.java
public class childfragment extends basefragment{ @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { return inflater.inflate(r.layout.fragment_child, container, false); } }
now, there textview in fragment_child layout. displayed when run app, there 2 other views in fragment_base, not showing...
extending fragment won't include views, views layout inflate, therefore won't see text views fragment_base in child fragment.
it might benefit instead create , use custom views/compound views can reuse in other fragments.
you can read on compound views here:
https://medium.com/@sserra90/android-writing-a-compound-view-1eacbf1957fc
Comments
Post a Comment