如何当返回到活动中保持Android的ListView的滚动位置? [英] How to retain Android ListView scroll position when returning to an activity?

查看:95
本文介绍了如何当返回到活动中保持Android的ListView的滚动位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/3014089/maintain-save-restore-scroll-position-when-returning-to-a-listview">Maintain/Save/Restore滚动位置时,返回到ListView

用户查看项目的列表视图,它们移动到一个活动,显示详细的一个项目,然后打回,并返回到列表中活动,但我想要的列表,以反映其先前的滚动位置。

The user views a listview of items, they move to an activity that shows detail for one item, and then hit Back and return to the list activity but I want the list to reflect its prior scroll position.

我应该存储滚动位置在上的onPause活动的成员变量,或是否有更好的办法吗?

Should I store the scroll position as a member variable on the activity in onPause or is there a better way?

推荐答案

节省的onPause和onResume检查在一个实例变量的位置,如果有位置值,并移动到它。

Save the position in an instance variable on onPause and in onResume check if there is position value and move to it.

例如。使用

private int currentPostion;

,然后在onResume做。

and then in onResume do..

getListView().setSelection(currentPosition);

这篇关于如何当返回到活动中保持Android的ListView的滚动位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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