explaingit

drakeet/multitype

5,766KotlinAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

MultiType is an Android library that makes it easy to build scrolling lists with many different visual styles. Each item type gets its own small class, so adding a new look never breaks existing code.

Mindmap

mindmap
  root((MultiType))
    Architecture
      Delegate classes
      Adapter registration
      One to many mapping
    Item Types
      Custom delegates
      Linker functions
      Visual styles
    Android Integration
      RecyclerView
      AndroidX
      Kotlin first
    Tooling
      Android Studio plugin
      Boilerplate generation
    Versioning
      v4 Kotlin only
      v3 Java compatible
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a social feed app where posts, images, and ads each look different in the same scrolling list

USE CASE 2

Create a settings screen with mixed row types such as toggles, headers, and buttons without tangled code

USE CASE 3

Add a new item style to an existing list without touching any of the code already written

USE CASE 4

Display the same data type in multiple visual formats depending on a flag inside the data

Tech stack

KotlinAndroidRecyclerViewAndroidX

Getting it running

Difficulty · easy Time to first run · 30min

Add the Maven dependency, create a delegate class per item type, register delegates with MultiTypeAdapter, and attach to your RecyclerView. AndroidX required. Use v3.x for Java projects.

Apache 2.0, free to use, modify, and distribute in personal or commercial projects with no restrictions beyond keeping the license notice.

In plain English

MultiType is an Android library written in Kotlin that makes it easier to build scrolling lists where different items in the list look different from each other. On Android, scrolling lists are typically built using a component called RecyclerView. By default, adding multiple visual styles to one list requires a fair amount of repetitive, error-prone code that becomes harder to change over time. MultiType is designed to remove that friction. The core idea is to separate each visual style into its own small class, called a delegate. Instead of one large adapter class that knows about every item type in the list, you register individual delegates with the adapter, one per type. When the list needs to display a particular kind of item, the adapter forwards that item to the matching delegate, which knows how to draw it. Adding a new item type means creating a new delegate class and registering it, none of the existing code needs to change. The library also supports a one-to-many mapping, where a single data type can be displayed in more than one way depending on the content of the item. A linker function inspects each item and decides which delegate should handle it. This handles cases like a feed where items of the same category should render differently based on some flag or value inside the data. An Android Studio plugin is available separately that generates the boilerplate files for a new item type automatically, reducing the setup work further. MultiType is licensed under the Apache 2.0 license. It requires AndroidX and is written fully in Kotlin from version 4 onwards. A legacy Java-compatible version (3.x) is available for projects that have not migrated.

Copy-paste prompts

Prompt 1
I am using the MultiType Android library. Show me how to create a delegate class in Kotlin for a news article item and register it with a MultiTypeAdapter.
Prompt 2
Using MultiType for Android, write a linker function that maps a single FeedItem data class to two different delegates based on a boolean field called isFeatured.
Prompt 3
I have a RecyclerView list using MultiType. Walk me through adding a brand new item type for a banner ad without changing any existing delegate or adapter code.
Prompt 4
Show me a complete minimal example of a MultiType setup in Kotlin: one adapter, two item types, two delegates, wired together in an Activity.
Prompt 5
I am migrating an Android project from Java to Kotlin. How do I switch from MultiType 3.x to 4.x and what breaking changes should I watch out for?
Open on GitHub → Explain another repo

← drakeet on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.