当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Event called when gridview/listview have been populated

问题描述:

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.
分享给朋友:
您可能感兴趣的文章:
随机阅读: