倒置的ListView在Android的? [英] Inverted ListView in Android?

查看:627
本文介绍了倒置的ListView在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,什么,我需要的是相反的。目前,我有一些讨厌的内部查询code,但觉得应该是基于倒车光标或简单的颠倒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管理器提供的API-演示。他们有大量的例子在那里。

also check the api-demos provided by the sdk manager . they have plenty of examples there.

这篇关于倒置的ListView在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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