6

Building a dictionary application I need a ListView that shows over 100k items. I want to let the user scroll as much as needed.

What's the best practice for searching and showing words?
Is it ok to show 150,000 words in the ListView (for pereformance)? If not how to add 100 other words after the user reaches to the end of the list?

Currently I show 50 words previous and 50 words next of searched word.

Thank you.

Heidar
  • 498
  • 1
  • 17
  • 35
  • Could you clarify your question: are you talking about helping the user scroll through the items, or how to respond to a user's search query? – Matthew Feb 24 '11 at 17:03
  • My problem is: is it ok to show 150,000 words in the ListView? If not how to add 100 other words after the user reaches to the end of the list? – Heidar Feb 25 '11 at 07:59

3 Answers3

9

(second answer in response to clarification about performance)

There are different ways to do this based on where your data is.

The best way is to have your data in a sqlite database and use a CursorAdapter. Android then manages the fetching of your data and won't fetch data that isn't currently being shown on the screen.

If your words are in an array in memory, try ArrayAdapter or SimpleAdapter.

The Adapter interface, from which all of the above classes inherit, is designed to provide good ListView performance regardless of the number of objects in the list.

Matthew
  • 44,826
  • 10
  • 98
  • 87
  • Thank you I will check and get back soon – Heidar Feb 25 '11 at 17:49
  • I'm having a similar problem using a TableLayout in a scrollView. The data is in an SQLite database which I read to memory and display. This takes forever though and it needs to be fairly close to instant. Can you provide a code sample for how to use the cursor adapter as you said? – ghostbust555 Jan 21 '12 at 02:34
2

One built-in way to allow fast scrolling is via the fast scroll thumb. In your xml, set:

android:fastScrollEnabled="true"

on your ListView, or try:

listView.setFastScrollEnabled(true)
listView.setFastScrollAlwaysVisible(true)
Matthew
  • 44,826
  • 10
  • 98
  • 87
0

RecyclerView is very good for this. I have developed an open source library especially designed to scroll through large list with extreme speed. In fact it can move well in excess of 1000 items per second both in single and multiple column layouts You can check out the repo here: https://bitbucket.org/warwick/hgfastlist or you can checkout the OpenGL version here: https://bitbucket.org/warwick/hgglfastlist. Here is a demo video on Youtube: https://www.youtube.com/watch?v=oz7aeAlOHBA&feature=youtu.be Even if you don't want to use this library, there's loads of code to read through in the demo app that will give you good ideas.

user2288580
  • 2,210
  • 23
  • 16