I have a a database with more than 6000 entries. I am using this example http://eshyu.wordpress.com/2010/08/15/cursoradapter-with-alphabet-indexed-section-headers/ to display the contents. But now the activity isn't able to handle it. I get a ANR dialog every time. How do I efficiently handle this circumstance?
Asked
Active
Viewed 123 times
0
-
2this part looks inefficent, it's visiting each entry and doesn't scale well: for (i = count - 1 ; i >= 0; i--){ sectionToPosition.put(indexer.getSectionForPosition(i), i);} – Phyrum Tea Jan 08 '11 at 19:49
1 Answers
1
It doesn't make sense to go through each entry and ask the indexer on wich section that entry belongs to. In your case, the Indexer might be doing 6000 binary searches. Then puting that result in a map that will have below 30 entries and doing many overwrites.
It's also not a good idea to abuse the sectionToPosition Map to create a section starting postion.
A. You either prepare a table containing the stats, which would be the best way to handle so much data.
B. You can use the database to count number of entries for each section and build your own section starting pos map.
SELECT UPPER(SUBSTR(LTRIM(side_a), 1, 1)), COUNT(*) FROM cards GROUP BY 1 ORDER BY 1 ASC;

Phyrum Tea
- 2,623
- 1
- 19
- 20
-
The main idea is, avoid reading all entries, only for those that must be visible. – Phyrum Tea Jan 09 '11 at 08:57
-
If you could post a snippet that would be really helpful. I'm just learning. Thank you @Phyrum Tea – Ragunath Jawahar Jan 10 '11 at 05:31