Android 滚动自动增长ListView
你好 我正在尝试根据网络内容构建一个列表视图。 我看过:
http://androidboss.com/load-listview-in -background-asynctask/
示例,但它使用预定义的月份数组。我该如何替代已知的 来自互联网的未知数量的未知项目的几个月? 我想加载一个列表视图,其中包含来自互联网的一些数据,用户 滚动列表并从互联网等检索下一行 而不是使用预定长度的数组。 谢谢伊恩
Hello
I am trying to build a listview based on content from the web.
I have had a look at :
http://androidboss.com/load-listview-in-background-asynctask/
example but it uses a predefined array of months. How can I substitute the known
array of months for an unknown undetermined number of items from the internet?
I want to load a listview with some data from the internet, the user
scrolls the list and it retrieves the next row(s) from the internet etc etc
rather than using a array of predetermined length.
Thanks Ian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用我的
EndlessAdapter
来实现这一点。该项目有一个演示其用途的demo/
子项目。You can use my
EndlessAdapter
for that. The project has ademo/
subproject demonstrating its use.听起来您需要扩展一个适配器,例如 ArrayAdapter。扩展 ArrayAdapter 以便您可以动态生成行或更改行数,并通知 Adapter 底层数据已更改,这是 Android 中非常常见的做法。
您会发现很多关于此的教程,但基本上,如果您通过扩展 ArrayAdapter 来实现自己的适配器,则可以重写 getView() 以编程方式生成每个视图,并且可以重写 getCount() 以提供行数。如果某些数据发生更改并且需要刷新,您可以使用notifyDataSetChanged()触发屏幕上列表的刷新。
It sounds like you need to extend an adapter such as ArrayAdapter. Extending an ArrayAdapter so that you can dynamically generate the rows or alter the number of rows, and also notify the Adapter that the underlying data has changed, is a very common exercise in Android.
You'll find quite a few tutorials on this but, very basically, if you implement your own adapter by extending ArrayAdapter you can override getView() to programmatically generate each view, and you can override getCount() to provide the number of rows. You can use notifyDataSetChanged() to trigger a refresh of the list on the screen if some data has changed and you need to refresh.