Android fragment inside the list

my application is a social network in which users exchange links and post them to allow them to receive. Basically, the main activity is just a list of messages. I use an open protocol analyzer to get metadata of web objects on the server side.

Now I need to display the correct layout in each message element depending on the metadata (video, application, web page, ...). And, of course, layouts must respond to user click events and call intent.

So, my first idea is to have a framelayout for each element, where I load a specific fragment that is responsible for creating the correct layout depending on the type of resource.

But I'm really not sure that loading a fragment inside a listview element is good practice, since the reuse system for views is completely confused.

I just wanted to know how best to implement this functionality for you guys.

Thank.

+3
source share
1 answer

This is actually not what fragments are for. You do not need to use fragments to have ListViewstrings of different types - just redefine getItemViewType()and getViewTypeCount()in ListAdapter, then be sure to create the correct string type on demand based on metadata.

+2
source

All Articles