I have a fragment containing a table (scrollable list). Each row of this table is a fragment too (subfragment). All these subfragments are created in the onCreateView
method of the root fragment and these subfragments do not have default (without arguments) constructors. I supposed that they do not need default constructors because there are no layouts with these subfragments and Android must call firstly the onCreatView
method and they all will be recreated. But it appeared that sometimes Android tries to call default constructors for them.
I can create for them default constructors and provide them with underlaying global data structures. But if Android creates all these subfragments by itself and then it calls the onCreateView
of the root fragment it may results in having two copies of all subfragments in the list! So I have some questons:
- Is it a bad practice to create some views or fragments in
onCreateView
and I am allowed only to callfindViewById
here? Should I do this inonCreate
or in the root fragment constructor? - Does Android call onCreate or
onCreateView
in the situation when it recreates the page this way?
Thanks for any answer!
You need to sign in to view this answers
Leave feedback about this