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:

  1. fragments inheritance android

  2. when need base activity , base fragment?

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...

enter image description here

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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -