Search code examples
androidfragmentvisibilitydrawerlayout

Is it good practice to create fragments and then change their visibility in Android?


I have a DrawerLayout menu made up of several elements. When the user chooses the option "Add new session" inside the menu, a form appears inside said DrawerLayout menu (by changing its visibility to VISIBLE) where the user can input his information. When the user clicks on "accept", the form disappears by changing its visibility to GONE.

This form is a layout of its own which is inflated from a fragment.

Is this good practice? What other methods are out there to achieve the same results?


Solution

  • This is perfectly acceptable. Another option would be to programmatically add the view when your "Add new session" option is selected and then remove it when you are finished with it, but in most cases it will be fine to just use VISIBLE and GONE.

    As a note, GONE view is inflated even though it is not visible.