mikepenz / FastAdapter

The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...
https://mikepenz.dev
Apache License 2.0
3.85k stars 493 forks source link

Clicked expandable item does not expand sometimes #1003

Open koral-- opened 3 years ago

koral-- commented 3 years ago

I need an expandable multi-level list where only one of top-level items can be expanded at a time but there is no such restrictions on lower levels (multiple items can be expanded there). Built-in isOnlyOneExpandedItem can't be used for that so I've implemented an onPreClickListener where I'm checking if top-level item is getting expanded, if so I'm collapsing everything else (items expanded on lower levels will be also collapsed and this is also expected).

It works fine if clicked item is above already expanded one but in an opposite case (expanding something below already expanded one) then clicked item is not getting expanded, only the previous expanded one gets collapsed.

Steps to reproduce:

  1. launch expandable sample
  2. collapse everything
  3. expand Test 6 item
  4. click on Test 3 item (it gets expanded and Test 6 gets collapsed - as expected)
  5. click on Test 6 item (Test 3 gets collapsed but Test 6 is not getting expanded)

What I've tried so far:

  1. returning true from onPreClickListener and toggling clicked item state manually
  2. adding notifyDataSetChanged call

Details

Checklist

mikepenz commented 3 years ago

Thank you very much for the report @koral--

Sounds like an interesting addition. Based on how special this usecase is, it would make sense to probably add it as a util allowing to have this be done when the user clicked on an element.

Happy to take a PR to expand functionality around this.