以编程方式滚动到 Android ListView 中的特定位置 [英] Programmatically scroll to a specific position in an Android ListView

查看:26
本文介绍了以编程方式滚动到 Android ListView 中的特定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式滚动到 ListView 中的特定位置?

How can I programmatically scroll to a specific position in a ListView?

比如我有一个String[] {A,B,C,D....},我需要设置ListView的顶部可见项code> 到我的 String[] 的索引 21.

For example, I have a String[] {A,B,C,D....}, and I need to set the top visible item of the ListView to the index 21 of my String[].

推荐答案

对于直接滚动:

getListView().setSelection(21);

为了平滑滚动:

getListView().smoothScrollToPosition(21);

这篇关于以编程方式滚动到 Android ListView 中的特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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