Ahmed Mostafa
Ahmed Mostafa

Reputation: 918

Fragments with multiple usage

Is it good practice to use a single Fragment with RecyclerView to display different data (Image with title or Image with title and description or only a title) using a different CustomAdapter and a different custom_item_view?

Or is it better to create a Fragment for each different type of data??

Upvotes: 0

Views: 36

Answers (2)

Davide
Davide

Reputation: 126

I have same needs (DrawerLayout, fragments and so on..) and for my purpose I choose to create more fragments; before all the code is more readable and you can easily change a part or if you want you can rewrite a fragment with less problems. Bye.

Upvotes: 1

Christine
Christine

Reputation: 5575

As Mariano says, it depends.

If the data is very similar, almost the same, you can use one Fragment. The problem with that is that as your app develops, the differences increase, and you get one Fragment with a lot of code that handles different types of data. The latter is an "anti pattern": it's something that happens often and is bad for code maintainability and testing.

I advise to use different Fragments, until your app has grown more or less stable, then determine if the Fragments are really almost the same, and if needed put them together.

Upvotes: 1

Related Questions