I have a TableLayout inside a ScrollView, 开发者_开发问答because of some special needs, I need to do some things when the ScrollView has reached the top. Is there such a listener to listen in on user's scrolling operations? Or, if there is no a ready listener, can I subclass the ScrollView (which will be painful I supposed) to achieve that? What methods do I need to implment? So far, I don't see a solution to this, but I hope it's only because I missed something .....
Thank you!
(In case you're wondering why I want to do this, here is some more background:
I have a flat-file database, I use a TableLayout to show the query results. When the query generates thousands of rows, the time spent on populating the table (using TableLayout.addView() to add rows) becomes unacceptable -- one minute on the emulator! And, there is a special need that when the table shows up, it has to be put at the LAST PAGE. That is, I have to populate the last few rows first, then grow upward, while the display remains unchanged when the table is growing. I tried two approaches so far, none was satisfactory. So I had to downgrade the requirement a little --- I don't populate all 3,000 rows at once, instead, I populate only the last couple of pages, like the last 40 rows or so. This way, the user will see the results displayed immediately. Then, if and when he decides to scroll up, when the program sees it, then I populate a few more pages, etc. Therefore, I need a listener or some way to detect when the table or the scroll view has reached the top. Thank you for reading up to this far!)
You might want to look into extending a BaseAdapter http://developer.android.com/reference/android/widget/ArrayAdapter.html and override getView(int position, View convertView, ViewGroup parent)
.
In that method you can check the position. So if you start out by populating your list with 10 items and the position is 10 then you know you've reached the bottom of your list and can add more items to your list. You know your at the top of your list if the position is 0. There's also a method in ListView to have your items start at the bottom ( like the messenger app ) http://developer.android.com/reference/android/widget/AbsListView.html#setStackFromBottom(boolean).
精彩评论