简体   繁体   中英

android - SimpleAdapter + SectionIndexer

I'm trying to use SectionIndexer in ListView using a SimpleAdapter.

I have about 30 elements in an array and the list is being built by considering every pair of the 30 elements except where each element in the pair is identical (ie i == j).

So each item in the list contains two text views and a checkbox. just to explain how the textviews are structured:

row1: textview1: afternoon(...) textview2: at(....)

row2: textview1: afternoon(...) textview2: battery_charging(....)

row3: textview1: afternoon(...)

etc etc

so basically every first TextView is the same until all pairs with that TextView have been consumed.

Since this list contains approximately 900(870 to be precise) entries I tried to implement SectionIndexing with FastScrolling.

While I understand how to do both, I seem to be running into a problem which I can't explain.

It looks like that when I scroll, the overlay that displays the current letter is always one ahead of the current position in the list.

I'm trying to work my head around this but I don't understand why.

I can post code, but I'm fairly sure I am not doing anything wrong.

The only flaw I can think of with this is the fact that all the words that begin with the same letter are identical.

thanks

it turned out I had to use this

 for (int i = size - 1; i >= 0; i--)

as opposed to

for (int i = 0; i<size; i++)

when I was creating the indexer map.

Just for the sake of interest, the reason the second for loop doesn't work is because each letter in the map is mapped to the last index of that letter.

Instead each letter has to map to the index when it first occurs. so for A it would be 0 and not 30 (where 30 is the number of items that start with A).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM