如何保持在Android的列表视图滚动条位置? [英] how to maintain scroll bar position in android listview?

查看:380
本文介绍了如何保持在Android的列表视图滚动条位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我在显示ListView控件数组。

I am displaying an array in ListView.

我改变动态按钮点击和呼叫

I change data of array dynamically on button click and call

adapter.notifyDataSetInvalidated();

但不维护列表的滚动条位置。 (数据源的列表中lenght始终是一样的)。 难道任何一个指导我如何保持ListView中的最后状态?

It does not maintain scroll bar position of list. (the lenght of data source to list is always same). Could any one guide me how to keep the last state of ListView ?

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

试试这个:

//Get the top position from the first visible element
int idx = list.getFirstVisiblePosition();
View vfirst = list.getChildAt(0);
int pos = 0;
if (vfirst != null) pos = vfirst.getTop();

//Restore the position
list.setSelectionFromTop(idx, pos);

这篇关于如何保持在Android的列表视图滚动条位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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