是否有滚动型的滚动一个监听? [英] Is there a listener for ScrollView's scrolling?

查看:161
本文介绍了是否有滚动型的滚动一个监听?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滚动型内TableLayout,由于某些特殊的需要,我需要做一些事情的时候滚动型已经达到了顶级。是否有这样的监听器窃听到用户的滚动操作?或者说,如果没有一个现成的听众,我可以继承的滚动型(这将是痛苦的我认为),以实现这一目标?我需要什么样的方法来implment?到目前为止,我没有看到一个解决的办法,但我希望那只是因为我错过了什么......

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 .....

感谢您!

(如果你想知道为什么我想这样做,这里有一些更多的背景:

(In case you're wondering why I want to do this, here is some more background:

我有一个平面文件数据库,我用一个TableLayout以显示查询结果。当查询生成数千行,时间上填充表花(使用TableLayout.addView()加行)变得不可接受 - 在模拟器上1分钟!当地而且,有一个特殊的需要,当表格显示时,它已经在最后一页被投入。也就是说,我必须先填充最后几排,然后向上生长,而显示当表增长保持不变。我尝试了两种方法到目前为止,还没有令人满意。所以我不得不降级的要求一点---我没有一次填充所有3000行,相反,我只填充的最后几页,就像过去的40行左右。以此方式,用户将看到立即显示的结果。那么,如果当他决定要向上滚动,程序看到它的时候,我填充几页,等等。因此,我需要一个听众或某种方式当表或滚​​动视图已经达到了顶级检测。感谢您的阅读远到这个!)

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!)

推荐答案

您可能要考虑延伸BaseAdapter的 http://developer.android.com/reference/android/widget/ArrayAdapter.html 并覆盖 getView(INT位置,查看convertView,父母的ViewGroup)
在这种方法中,你可以检查的位置。所以如果你开始通过填充有10个项目列表和位置是10,那么你知道你已经达到了您的列表的底部,可以到你的列表中添加更多的项目。你在你的列表顶部知道你如果位置为0还有在ListView控件的方法让您的项目在底部启动(如Messenger应用)<一个href=\"http://developer.android.com/reference/android/widget/AbsListView.html#setStackFromBottom(boolean\" rel=\"nofollow\">http://developer.android.com/reference/android/widget/AbsListView.html#setStackFromBottom(boolean).

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).

这篇关于是否有滚动型的滚动一个监听?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆