Android 中的倒置 ListView? [英] Inverted ListView in Android?
问题描述
有没有一种简单的方法可以以相反的顺序显示 ListView?我正在尝试创建一个基于对话的应用程序,并希望最近的条目位于 ListView 的底部.我知道transcriptMode 和stackFromBottom,但是我的问题是数据的顺序.
Is there an easy way to display a ListView in reverse order? I am trying to create a conversation-based app, and would like the most recent entries to be at the bottom of the ListView. I am aware of transcriptMode and stackFromBottom, however my problem is the order of the data.
假设我有 100 个对话项目,并且想要显示 80-100 个项目,其中 100 是最近的对话项目.我想显示 80-100,这意味着在我的查询中使用 ORDER BY id desc LIMIT 20,这会强制将项目按 100 到 80 排序,这与我需要的相反.我目前有一些讨厌的内部查询代码,但我觉得应该有一个更简单的解决方案,即反转光标或简单地反转 ListView.
Say I have 100 conversation items, and want to display items 80-100, with 100 being the most recent conversation item. I would like to show 80-100, which implies an ORDER BY id desc LIMIT 20 in my query, which forces the items to be sorted 100 to 80, the opposite of what I need. I currently have some nasty inner query code, but feel like there should be a simpler solution based on reversing the cursor or simply inverting the ListView.
推荐答案
在baseAdapter
内部,用于getView()
方法,而不是获取索引位置"中数据中的项目,而是使用相反的方法,意思是:numberOfItems 减去位置.
inside the baseAdapter
, for the getView()
method , instead of getting the item in the data in index "position" , use the opposite , meaning : numberOfItems minus the position .
至于显示项目数,这也在 baseAdapter 中:将 getCount()
返回的值设置为您希望的值(在您的示例中为 20,尽管 80-100 意味着它应该是 21 ) .
as for showing the number of items , that's also inside the baseAdapter : set the value returned by getCount()
to be the one you wish it to be (20 in your example,though 80-100 implies that it should be 21 ) .
顺便说一句,在 listView 的情况下,您似乎是初学者.我可以建议观看这个视频吗:http://www.youtube.com/watch?v=wDBM6wVEO70
btw, it seems you are a starter in the case of listView . may i suggest watching this video: http://www.youtube.com/watch?v=wDBM6wVEO70
还要检查 sdk manager 提供的 api-demos.他们有很多例子.
also check the api-demos provided by the sdk manager . they have plenty of examples there.
这篇关于Android 中的倒置 ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!