0

I cannot find a way to expand nested items using FastAdapter library.

Example:
Category 1
  -- Subcategory 1 // Subitem of category
    ++ SubSubCategory 1 // Subitem of subcategory
    ++ SubSubCategory 2
  -- Subcategory 2
    ++ SubSubCategory 3
    ++ SubSubCategory 4
Category 2
  -- Subcategory 1
  -- Subcategory 2

I'd like to expand "SubSubCategory 2". It works when I'm doing it manually, by clicking (obviously). But in some cases, I'd like to open it programmatically. I know how to do it if I'd like to open Subcategory - getExpandableExtension().expand(globalPosition). But how can I do that with SubSubCategory? I don't know any way to get their position. Changing isExpanded flag also doesn't help. I know the identifier of the item I'd like to open.

Jakub Mosakowski
  • 469
  • 1
  • 7
  • 15

1 Answers1

1

UPDATE: It is now possible with the usage of the method expandAllOnPath that was added in v5.2.2.

Thanks to the author of the library I realized why I couldn't find the nested object. I should have expanded it layer by layer, so first categories, then subcategories.

private fun expand(item: GenericItem) {

  // Get position of the item.
  val relativePosition = myAdapter.itemAdapter.getAdapterPosition(item)
  val globalPosition = myAdapter.itemAdapter.getGlobalPosition(relativePosition)

  // Expand item.
  categoriesAdapter.getExpandableExtension().expand(globalPosition)
}

Finally, I simply used the above method twice, the first level then the next one.

Jakub Mosakowski
  • 469
  • 1
  • 7
  • 15
  • I added also a PR to the library which adds the possibility to recursively open items, maybe it will be accepted and added in a new version. https://github.com/mikepenz/FastAdapter/pull/912 – Jakub Mosakowski Jul 17 '20 at 06:19