使用 scrollTo ListView 时不刷新,但手动滚动时刷新 [英] When using scrollTo ListView does not refresh, but when manually scrolling it refreshes

查看:23
本文介绍了使用 scrollTo ListView 时不刷新,但手动滚动时刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过根据行号(在 Adapter 的 getView() 中)设置文本框的颜色,我为 ListView 中的不同行设置了不同的颜色.现在,当我手动向上滚动 ListView 时,正确的颜色显示在显示的底部行中.但是当我使用 scrollTo 时,这不会发生,显示的所有行都具有相同的颜色(它们没有更新).

I have different colors for different lines in the ListView, by setting the color of textbox depending on the line number (in getView() of Adapter). Now when I manually scroll the ListView upwards the correct color is displayed in the bottom lines that get revealed. But when I use scrollTo, this doesnot happen, all lines revealed have the same color (they are not updated).

有人遇到过这个问题吗?这似乎令人费解!

Has anybody faced this issue? This seems baffling!

推荐答案

ListView#scrollTo 不滚动列表内容.(这是一个标准的 View 方法,根本不特定于列表:它滚动 ListView 视图本身.)

ListView#scrollTo doesn't scroll the list contents. (It's a standard View method, and not specific to lists at all: it scrolls the ListView view itself.)

相反,尝试使用 ListView#setSelectionFromTop(0, int y) 来滚动.

Instead, try using ListView#setSelectionFromTop(0, int y) to scroll.

API 19+ 有一个 ListView#scrollListBy(int y) 方法,如果你正在为 KitKat 及更高版本编程.

API 19+ has a ListView#scrollListBy(int y) method if you're programming for KitKat and up.

这篇关于使用 scrollTo ListView 时不刷新,但手动滚动时刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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