Skip to content

[Lists] MultiSectionListDemo crashes in case SubHeader at first position #4987

@patrickfrei

Description

@patrickfrei

Description: The Catalog example MultiSectionListDemo crashes in case we define a SubHeader item or multiple CustomList items at the top of the overall list. The example is currently only working in case there is one single item at the first position, but there are further use cases than that, as just mentioned.

Minimal sample app repro: In the Catalog demo....

  1. Open file MultiSectionListDemoFragment.java
  2. Go to line 54
  3. Between lines 54 and 55, insert data.add(new CustomListItemData("Subheader TEST"));
  4. Final code snippet as of line 53:
List<CustomListItemData> data = new ArrayList<>();
int itemCount = 0;
data.add(new CustomListItemData("Subheader TEST"));
data.add(
        new CustomListItemData(
            String.format(view.getContext().getString(R.string.cat_list_item_text), 0), 0, 1));

This will make the app crashing due to a type cast error in onBindViewHolder. Probably, because the view type cannot be correctly derived as the index is missing.

The app is crashing as well if you add e.g. the following at the first position:

for (int i = 0; i < 3; i++) {
   data.add(
      new CustomListItemData(
         String.format( view.getContext().getString(R.string.cat_list_item_text), itemCount + i), i,3));
}

Android API version: 16

Material Library version: 1.14.0-alpha08

Device: Google Pixel 9 Pro

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions