On Fri, Nov 12, 2010 at 7:50 AM, Alex Xin <[email protected]> wrote: > I have a list view with array adapter to show user > some information that retrieved from Internet, As we all know reading data > from Internet requires some time to finish, but if I try to read data on > getView(), it means user must wait and he/she cannot see anything at that > time, the screen is black for long a time because it will cost too much time > to finish. This is unacceptable.
Correct. Your application will also crash. > So I think maybe I can show user a empty list view first and then display a > progress dialog to let user know I'm now just reading data. The background > task will read data and send message to UI thread when job is done. That seems reasonable. > But > there's one problem: I don't know how to get notified when list view is > displayed. I mean, I want to know when & where to show that progress dialog > when I first show user an empty list? Step #1: Call setContentView() with a layout containing your ListView Step #2: Spawn your AsyncTask to load your data into the ListView Here is a sample project showing how to use an AsyncTask to fill in a ListView: https://github.com/commonsguy/cw-android/tree/master/Threads/Asyncer/ In my case, I fill in the ListView progressively and show a Toast at the end, rather than fuss with a ProgressDialog. Also note that my implementation there does not show how to deal with orientation changes and the AsyncTask, because I cover that point later in my book. Here is a sample of a AsyncTask that works well with an orientation change: https://github.com/commonsguy/cw-android/tree/master/Rotation/RotationAsync/ -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

