lundi 25 avril 2016

Is there an Android design pattern to handle multiple fragments in a single activity?

I inherited some code at work and I have a question about some implementation. The application I'm working on has an Activity that contains about 15 different fragments. The logic in the Activity handling these fragments can roughly be summarized with the following pseudocode:

if (button_1 selected) { 
    load fragment_1; 
} else if (button_2 selected) {
    load fragment_2;
} else if (button_3 selected) {
    load fragment_3;
} ...and so on x15ish

My question is: does there exist some kind of Android design pattern to handle situations like this? The code works; however, I don't feel too comfortable with a giant if/else or case statement. I saw this question and it seems very similar to the problem that I'm having. I did quite a bit of searching on the internet but I haven't found examples or best practices for this kind of scenario.

If someone can point me in the right direction or have some suggestions; that'd be awesome. Thanks!

Aucun commentaire:

Enregistrer un commentaire