简体   繁体   English

Android 滚动自动增长列表视图

[英]Android Scrolling Autogrow ListView

Hello I am trying to build a listview based on content from the web.您好,我正在尝试根据 web 的内容构建列表视图。 I have had a look at:我看过:

http://androidboss.com/load-listview-in-background-asynctask/ 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谢谢伊恩

You can use my EndlessAdapter for that.你可以使用我的EndlessAdapter The project has a demo/ subproject demonstrating its use.该项目有一个demo/子项目演示其使用。

It sounds like you need to extend an adapter such as ArrayAdapter.听起来您需要扩展一个适配器,例如 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.扩展 ArrayAdapter 以便您可以动态生成行或更改行数,并通知 Adapter 底层数据已更改,这是 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.你会发现很多关于这个的教程,但是,基本上,如果你通过扩展 ArrayAdapter 来实现你自己的适配器,你可以覆盖 getView() 以编程方式生成每个视图,你可以覆盖 getCount() 来提供行数。 You can use notifyDataSetChanged() to trigger a refresh of the list on the screen if some data has changed and you need to refresh.如果某些数据已更改并且您需要刷新,您可以使用 notifyDataSetChanged() 来触发屏幕上列表的刷新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM