如何显示在列表视图中的最后一个项目,当滚动动态获取新项目? [英] How to show the last item in the List View when scrolled to get new items dynamically?

查看:137
本文介绍了如何显示在列表视图中的最后一个项目,当滚动动态获取新项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序的列表视图,显示10个项目开始,当我滚动的底部,它动态地增加了10个项目每次。我的问题是,当我滚动到底部,显示屏将在列表中(而不是新添加的10个项目)的第一个项目,所以我需要滚动一路下跌。

I have a list view in my app which shows 10 items initially, and when i scroll to the bottom, it dynamically adds 10 items every time. My problem is when i scroll to the bottom, the display goes to the 1st item in the list(not the newly added 10 items), so i need to scroll all the way down.

我用

ListView.setSelection(totalItemCount - 9);

要显示新加入的10个项目的第一个项目。但在这里发生的事情是,显示屏将到ListView真正的第一个项目,但同样它会自动滚动到新添加的10个项目的第一个项目。因此,对UX会坏在这里....我希望它改变,因此,它不对子级去列表视图的顶部。希望我解释清楚,请大家帮帮忙,三江源

to display the 1st item of the newly added 10 items. But here what happens is the display goes to the 1st item of the listview actually, but again it automatically scrolls to the 1st item of the newly added 10 items. so, the ux will be bad here....i want it to change so that it whould not go to the top of the listview. hope i explained it clearly, please help, thankyou

推荐答案

当你向下滚动并开始获得新的数据应该存储在使用这种方法的一些变量,你上次看见的位置:

When you scroll down and start getting new data you should store your Last Visible Position in some variables using this method :

int firstVisiblePosition = listView.getFirstVisiblePosition();

修改 试试这个:

View view = listView.getChildAt(0);
int distFromTop = (view == null) ? 0 : view.getTop();

然后你完成加载数据,你应该使用设置这个位置之后:

Then after you completed loading data you should set this position using :

listView.setSelectionFromTop(firstVisiblePosition, distFromTop);

这篇关于如何显示在列表视图中的最后一个项目,当滚动动态获取新项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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