Inverted ListView in Android?

后端 未结 4 2099
谎友^
谎友^ 2020-12-11 03:39

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 th

相关标签:
4条回答
  • 2020-12-11 04:17

    Query for records using BETWEEN keyword seems like the easiest solution to me.

    0 讨论(0)
  • This code is worked for me when pulling data from database.

    cs.moveToPosition(super.getCount() - position - 1); //cs is Cursor
    
    0 讨论(0)
  • 2020-12-11 04:25

    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 .

    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 ) .

    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

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

    0 讨论(0)
  • 2020-12-11 04:31

    Use this getItem Method inside your Adapter for reverse order:

    @Override
    public Object getItem(int position) {
       return super.getItem(super.getCount() - position - 1);
    }
    
    0 讨论(0)
提交回复
热议问题