Hi everyone, I have a question about Android, but ...
# android
n
Hi everyone, I have a question about Android, but not related to Kotlin (sorry). 1. Is it a good practice to use multiple fragments on one activity? 2. Is where any rules, best practices when to choose layout inside fragment, and when to move it to separate fragment?
a
@Nikolai Use Navigation component for using multiple fragments in the same activity, more details check out https://developer.android.com/guide/navigation/navigation-getting-started. Your second question is not clear me, what do want to know
n
Thanks for your answer. Second question is about selecting between fragment and layout. For example, I have fragment inside activity. And some group of controls what need to be placed on same screen, united by function they do. Group of buttons, button + text field or something like this. So, should I place them inside same fragment but separate in nested layout or don’t separate at all. Or I should move them to separate fragment and put two fragments on one screen? Is there any rules, best practices to make those decisions?
Sorry, if I am not clear
n
If there are some same UI elements in all the fragments you can place them inside the activity. We have checkout process in our app. One activity and several fragments. The button to continue is on the activity and it's changed based on the fragments the client is on
a
@Nikolai, Then you can remove View from your parent layout based on your logic and can add new View. If number off View is more to manage in this way then you can use ViewPager2
n
Thank you all for answering