Skip to content

[List] Dynamic number of list items #5001

@patrickfrei

Description

@patrickfrei

Description: The M3 Catalog app contains several List examples. The number of list items in these examples is static. However, there are use cases, where the number of items is dynamic. Consider the following example:

i=0;
listData.add(new CustomListItemData("Item A", i++, 20));
listData.add(new CustomListItemData("Item B", i++, 20));
if (x=y) {
  listData.add(new CustomListItemData("Item X", i++, 20));
  listData.add(new CustomListItemData("Item Y", i++, 20));
}
listData.add(new CustomListItemData("Item C", i++, 20));
listData.add(new CustomListItemData("Item D", i  , 20));

In this case, we can set indexInSection for each item by incrementing an integer variable (i++) that starts at 0. However, when starting to populate the above listData array, it's not yet known how many items the final list will contain. It can be either 4 or 6. So, it's unclear to me what numbers have to be added for sectionCount for each item.

Requirement: How should we handle such a use case when using a List with a dynamic number of items (sectionCount)?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions