滚动到列表视图时加载数据 [英] Load data when scrolling to listview

查看:131
本文介绍了滚动到列表视图时加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当用户滚动加载数据。加载的数据是结合在ListView控件的末尾。
我测试此功能。我发现在Android的。但我用这个当在列表装载的最终用户滚动仍出现并不能点击的ListItem无尽的滚动。我怎么能知道什么时候结束的数据?

I want to load data when user scroll . The loaded data is combine at the end of the ListView. I test this feature . I found endless scroll in android .But I use this when the user scroll at the end of the list loading still appear and can't click on listitem . How can I know when the data end ?

推荐答案

例如,您可以您的getView方法中使用code:

For example, you could use this code within your getView method:

@Override
public View getView(final int position, View row, final ViewGroup parent) {

...
  if (position > lastViewed && position == getCount()-1) {
      lastViewed = position;
      runTask(); //I immagine an AsyncTask which fetch data from the net or from a local  db
  }
...
}

当然在你的假设的AsyncTask 您不必清除适配器上preExecute只是增加新的项目。

Of course in your hypothetical AsyncTask you do not have to clear the adapter on onPreExecute but just adding the new items.

很抱歉,但问题是有点过于笼统,不知道你的$ C $的stucture c将其自带复杂的回答,反正我希望这会有所帮助。

Sorry but the question is a bit too generic, without knowing the stucture of your code it comes complicated to answer, anyway I hope it will help.

这篇关于滚动到列表视图时加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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