سؤال

With a complex adapter, GridViews and ListViews can sometimes take a long time to populate after calling the setAdapter() method. Is there a method we can override that is triggered when the view has been successfully populated with data and is ready to be shown?

هل كانت مفيدة؟

المحلول

My feeling is that it isn't the setAdapter() that takes a long time, but rather that the complex adapter is doing something complex. The ListView and GridViews are specified to work rather quickly, but there's a few reasons they might be slower. Here's a few thoughts as to how to work this one out.

  1. Figure out what's taking so long. Network calls, large database queries, and loading large files (Bitmaps in particular) are often the guilty party. If you don't have any of those, try profiling your code, and see what you can gleam from that.
  2. Once you've figured out the culprit, see what you can do to decrease the amount of time. Perhaps shrinking the size of a bitmap, or using a better database query would work.
  3. If you can't shrink the time down any more, then do the complex task in an AsyncTask. This will do the complex part of your code in the background, and only show the result when it is complete. This works well for things like network calls, loading bitmaps, etc.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top