如何使光标适应具有大量自定义行为的 ListView?
我目前正在开发一个 Android 应用程序,该应用程序使用 SimpleCursorAdapter
和自定义 ViewBinder
来设置 ListView
。
但是,当我的列表比屏幕大小长,并且用户上下滚动时,系统会导致不正确的行呈现错误的颜色等。我的理解是,这是系统重用的问题视图作为滚动优化,如此处所述。
我完全支持优化,但是我需要项目在 ListView
中正确显示。正确的做法是什么?
我的想法是,我可以实现一个 CursorAdapter,或者最好是一个 SimpleCursorAdapter,但我不知道如何去做。或者,是否只需在我的 ViewBinder
中将文本颜色设置回默认值即可?
I'm currently working on an android application that uses a SimpleCursorAdapter
with a custom ViewBinder
to set specific text color and image visibility on items in my ListView
.
However, when my list is longer then the size of a screen, and the user scrolls up and down, the system causes incorrect rows to take on the wrong coloring, etc. My understanding is that this is an issue of the system re-using views as an optimization in scrolling, as explained here.
I'm all for optimization, however I need items to display properly in the ListView
. What is the correct way to go about this?
My thinking is that I could implement a CursorAdapter
, or preferably a SimpleCursorAdapter
, but I don't know how to go about doing so. Alternatively, is it just a matter of setting text color back to its default in my ViewBinder
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是在 getView() 中将每一行设置为正确的颜色/值等的问题。至于 simpleCursorAdapter - 我找到了一个很好又简单的教程: http:// /thinkandroid.wordpress.com/2010/01/09/simplecursoradapters-and-listviews/
Yes, it is a matter of setting every row to a proper color/ values etc. in getView(). As to the simpleCursorAdapter - I found a nice and simple tutorial: http://thinkandroid.wordpress.com/2010/01/09/simplecursoradapters-and-listviews/