mth.vidal
mth.vidal

Reputation: 178

android fragment inside listview

my app is a social network where users share links and tag them to let the right persons receive it. Basically, the main activity is simply a listview of posts. I use an open protocol parser to get the web objects metadata on server side.

Now I need to display the right layout in each post item depending of the metadata (video, app, web page, ...). And of course, layouts must react to user clicks event and call intents.

So my first idea is to have a framelayout for each item where I load a specific fragment in charge of generating the right layout depending of the resource type.

But I'm really not sure loading a fragment inside a listview item is a good practice as the reuse system of views is totally messed up.

I'd just like to know what is the best way to implement this functionality for you guys.

Thank you.

Upvotes: 3

Views: 2140

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006584

This is not really what fragments are designed for. You do not need to use fragments to have ListView rows of differing types -- just override getItemViewType() and getViewTypeCount() in your ListAdapter, then be sure to create the right type of row on demand based upon the metadata.

Upvotes: 2

Related Questions