Show / Hide Listview SectionIndex on request

i implemented a listview that implements SectionIndexer ... all still.

Typically, items are sorted by name, but I also offer the ability to sort the list differently - by distance (from user to objects).

So, when the list is sorted by the second path, I want to hide the previously createdIndex section.

I just can't do it.

I tried, rewrote most of the methods, I tried it with separation in the constructor (it’s clear why it doesn’t work, it doesn’t get called the second time) I even tried it with the implementation of the second listadapter, and just used another? Even so, SEctionIndex is shown! I really don't get it.

So it would be great if someone knows what is happening :)

Thanks a lot mike

+6
source share
3 answers

Your observations are correct. Let me first tell you why the constructor will never be called a second time. The Indexer section is a special view. They create an index only once for a specific data set and reuse them on this adapter. The big problem I ran into was that when the underlying data changed for the adapter, the Indexer section was still the same.

Check out my Question and answer there.

Returning to your request here.

If you change the orientation after selecting the second option, you will see that the constructor will be called, and you will be able to populate sectionIndex again. So basically you need to call onSizeChanged again and get the reponulated sectionIndex.

+2
source

When you shorten your list in another way, you have two more options for downloading.

after filling out a new adapter collection

1) you can report this to the adapter.

2) you can fill out the adapter kit again.

0
source

If you see a section label as indicated by SectionIndexer, you can achieve this by calling setFastScrollEnabled (false) before switching to another list that SectionIndexer does not implement.

0
source

Source: https://habr.com/ru/post/893454/


All Articles