Build a list using multiple item types

You can use a list with multiple item types to display mixed content types such as text, images, and interactive elements.

Version compatibility

This implementation requires that your project minSDK be set to API level 21 or higher.

Dependencies

Add multiple item types

You can specify the content type for each item of the layout when you compose a list or a grid with multiple types of items:

Key points about the code

  • Specifies the content type for each item by setting contentType in items().
  • Maps each content type to a corresponding composable. For example, Audio is a contentType that is defined elsewhere and is mapped to an AudioMessage composable.
  • Compose reuses the rendered composables for each item of a given content type.

Results

Code output showing audio and text messages
Figure 1. Code output showing audio and text messages.

Parent collections

Lists and grids allow your app to display collections in a visually pleasing form that's easy for users to consume.
Learn how composable functions can enable you to easily create beautiful UI components based on the Material Design design system.
This series of videos introduces various Compose APIs, quickly showing you what’s available and how to use them.

Have questions or feedback

Go to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts.